TextEdit: don't set response.changed() when cursor changes

This commit is contained in:
Emil Ernerfeldt 2021-06-12 15:02:33 +02:00
parent 508f6d9bf5
commit f4a95b1e5f
2 changed files with 7 additions and 3 deletions

View file

@ -273,8 +273,12 @@ impl Response {
///
/// e.g. the slider was dragged, text was entered in a `TextEdit` etc.
/// Always `false` for something like a `Button`.
///
/// Can sometimes be `true` even though the data didn't changed
/// (e.g. if the user entered a character and erased it the same frame).
///
/// This is not set if the *view* of the data was changed.
/// For instance, moving the cursor in a `TextEdit` does not set this to `true`.
#[inline(always)]
pub fn changed(&self) -> bool {
self.changed
@ -284,6 +288,9 @@ impl Response {
///
/// This must be called by widgets that represent some mutable data,
/// e.g. checkboxes, sliders etc.
///
/// This should be called when the *content* changes, but not when the view does.
/// So we call this when the text of a [`crate::TextEdit`], but not when the cursors changes.
#[inline(always)]
pub fn mark_changed(&mut self) {
self.changed = true;

View file

@ -471,7 +471,6 @@ impl<'t, S: TextBuffer> TextEdit<'t, S> {
primary: galley.from_ccursor(ccursorp.primary),
secondary: galley.from_ccursor(ccursorp.secondary),
});
response.mark_changed();
} else if response.hovered() && ui.input().pointer.any_pressed() {
ui.memory().request_focus(id);
if ui.input().modifiers.shift {
@ -483,11 +482,9 @@ impl<'t, S: TextBuffer> TextEdit<'t, S> {
} else {
state.cursorp = Some(CursorPair::one(cursor_at_pointer));
}
response.mark_changed();
} else if ui.input().pointer.any_down() && response.is_pointer_button_down_on() {
if let Some(cursorp) = &mut state.cursorp {
cursorp.primary = cursor_at_pointer;
response.mark_changed();
}
}
}