add methods to manipulate TextEditState undoer (#3479)

This feels awful, @emilk why does this have to be an Arc?

Should the Arc be replaced with a new one when set_undoer is called, or
should it just replace the undoer inside the Arc?

Closes #3436
This commit is contained in:
LoganDark 2024-01-07 08:19:37 -08:00 committed by GitHub
parent 5432f91a4d
commit 327f599407
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -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<Mutex<Undoer>>,
pub(crate) undoer: Arc<Mutex<TextEditUndoer>>,
// 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<CursorRange> {
self.cursor_range
.map(|cursor_range| {