From 845533654be102af4c5e40cf5cee2a1a93f9a67b Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Wed, 1 Oct 2025 18:26:25 +0600 Subject: [PATCH] fix(editor)!: undo requires two presses after copy Previously all copy commands created redundant undo point, this commit resolves this by not creating an undo point when EditType is NoOp --- src/core_editor/editor.rs | 6 +++--- src/enums.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core_editor/editor.rs b/src/core_editor/editor.rs index 96e8e911..aeeb6e03 100644 --- a/src/core_editor/editor.rs +++ b/src/core_editor/editor.rs @@ -194,7 +194,7 @@ impl Editor { let deleted_char = self.edit_stack.current().grapheme_left().chars().next(); UndoBehavior::Backspace(deleted_char) } - (_, EditType::UndoRedo) => UndoBehavior::UndoRedo, + (_, EditType::UndoRedo | EditType::NoOp) => UndoBehavior::NoOp, (_, _) => UndoBehavior::CreateUndoPoint, }; @@ -307,8 +307,8 @@ impl Editor { } pub(crate) fn update_undo_state(&mut self, undo_behavior: UndoBehavior) { - if matches!(undo_behavior, UndoBehavior::UndoRedo) { - self.last_undo_behavior = UndoBehavior::UndoRedo; + if matches!(undo_behavior, UndoBehavior::NoOp) { + self.last_undo_behavior = UndoBehavior::NoOp; return; } if !undo_behavior.create_undo_point_after(&self.last_undo_behavior) { diff --git a/src/enums.rs b/src/enums.rs index 41531ba2..84f39ee9 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -615,9 +615,9 @@ impl EditCommand { #[cfg(feature = "system_clipboard")] EditCommand::CopySelectionSystem => EditType::NoOp, EditCommand::CutInsidePair { .. } => EditType::EditText, - EditCommand::CopyInsidePair { .. } => EditType::EditText, + EditCommand::CopyInsidePair { .. } => EditType::NoOp, EditCommand::CutAroundPair { .. } => EditType::EditText, - EditCommand::CopyAroundPair { .. } => EditType::EditText, + EditCommand::CopyAroundPair { .. } => EditType::NoOp, EditCommand::CutTextObject { .. } => EditType::EditText, EditCommand::CopyTextObject { .. } => EditType::NoOp, EditCommand::CopyFromStart @@ -674,8 +674,8 @@ pub enum UndoBehavior { /// Catch-all for actions that should always form a unique undo point and never be /// grouped with later edits CreateUndoPoint, - /// Undo/Redo actions shouldn't be reflected on the edit stack - UndoRedo, + /// For actions that shouldn't be reflected on the edit stack e.g. Undo/Redo + NoOp, } impl UndoBehavior {