diff --git a/crates/egui/src/widgets/text_edit/state.rs b/crates/egui/src/widgets/text_edit/state.rs index b4c408619f9..ef863eded2e 100644 --- a/crates/egui/src/widgets/text_edit/state.rs +++ b/crates/egui/src/widgets/text_edit/state.rs @@ -6,7 +6,7 @@ use crate::*; use super::{CCursorRange, CursorRange}; -type Undoer = crate::util::undoer::Undoer<(CCursorRange, String)>; +pub type TextEditUndoer = crate::util::undoer::Undoer<(CCursorRange, String)>; /// The text edit state stored between frames. /// @@ -42,7 +42,7 @@ pub struct TextEditState { /// Wrapped in Arc for cheaper clones. #[cfg_attr(feature = "serde", serde(skip))] - pub(crate) undoer: Arc>, + pub(crate) undoer: Arc>, // If IME candidate window is shown on this text edit. #[cfg_attr(feature = "serde", serde(skip))] @@ -81,6 +81,18 @@ impl TextEditState { self.ccursor_range = None; } + pub fn undoer(&self) -> TextEditUndoer { + self.undoer.lock().clone() + } + + pub fn set_undoer(&mut self, undoer: TextEditUndoer) { + *self.undoer.lock() = undoer; + } + + pub fn clear_undoer(&mut self) { + self.set_undoer(TextEditUndoer::default()); + } + pub fn cursor_range(&mut self, galley: &Galley) -> Option { self.cursor_range .map(|cursor_range| {