fix: keep the cursor at the end if it previously when diffing

This commit is contained in:
Ashley Wulber 2024-07-29 16:41:15 -04:00 committed by Michael Murphy
parent 2170a65c89
commit 22138671b4

View file

@ -542,16 +542,15 @@ where
state.is_pasting = None;
state.dragging_state = None;
}
let old_value = state
.value
.buffer()
.lines
.iter()
.map(|l| l.text())
.collect::<String>();
if state.is_secure != self.is_secure
|| state
.value
.buffer()
.lines
.iter()
.map(|l| l.text())
.collect::<String>()
!= self.value.to_string()
|| old_value != self.value.to_string()
|| state
.label
.buffer()
@ -585,6 +584,19 @@ where
});
}
// if the previous state was at the end of the text, keep it there
let old_value = Value::new(&old_value);
if state.is_focused.is_some() {
match state.cursor.state(&old_value) {
cursor::State::Index(index) => {
if index == old_value.len() {
state.cursor.move_to(self.value.len());
}
}
_ => {}
};
}
let mut children: Vec<_> = self
.leading_icon
.iter_mut()