Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to load/store TextEditState undoer #3479

Merged
merged 1 commit into from
Jan 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions crates/egui/src/widgets/text_edit/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -42,7 +42,7 @@ pub struct TextEditState {

/// Wrapped in Arc for cheaper clones.
#[cfg_attr(feature = "serde", serde(skip))]
pub(crate) undoer: Arc<Mutex<Undoer>>,
pub(crate) undoer: Arc<Mutex<TextEditUndoer>>,

// If IME candidate window is shown on this text edit.
#[cfg_attr(feature = "serde", serde(skip))]
Expand Down Expand Up @@ -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<CursorRange> {
self.cursor_range
.map(|cursor_range| {
Expand Down
Loading