diff --git a/egui/src/response.rs b/egui/src/response.rs index 0c6ebf6e..78d215ab 100644 --- a/egui/src/response.rs +++ b/egui/src/response.rs @@ -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; diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index 3e9cd2be..f1ae8e25 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -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(); } } }