Skip to content

Commit a48fc93

Browse files
committed
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
1 parent 77137e3 commit a48fc93

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/core_editor/editor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl Editor {
194194
let deleted_char = self.edit_stack.current().grapheme_left().chars().next();
195195
UndoBehavior::Backspace(deleted_char)
196196
}
197-
(_, EditType::UndoRedo) => UndoBehavior::UndoRedo,
197+
(_, EditType::UndoRedo | EditType::NoOp) => UndoBehavior::NoOp,
198198
(_, _) => UndoBehavior::CreateUndoPoint,
199199
};
200200

@@ -307,8 +307,8 @@ impl Editor {
307307
}
308308

309309
pub(crate) fn update_undo_state(&mut self, undo_behavior: UndoBehavior) {
310-
if matches!(undo_behavior, UndoBehavior::UndoRedo) {
311-
self.last_undo_behavior = UndoBehavior::UndoRedo;
310+
if matches!(undo_behavior, UndoBehavior::NoOp) {
311+
self.last_undo_behavior = UndoBehavior::NoOp;
312312
return;
313313
}
314314
if !undo_behavior.create_undo_point_after(&self.last_undo_behavior) {

src/enums.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,9 @@ impl EditCommand {
615615
#[cfg(feature = "system_clipboard")]
616616
EditCommand::CopySelectionSystem => EditType::NoOp,
617617
EditCommand::CutInsidePair { .. } => EditType::EditText,
618-
EditCommand::CopyInsidePair { .. } => EditType::EditText,
618+
EditCommand::CopyInsidePair { .. } => EditType::NoOp,
619619
EditCommand::CutAroundPair { .. } => EditType::EditText,
620-
EditCommand::CopyAroundPair { .. } => EditType::EditText,
620+
EditCommand::CopyAroundPair { .. } => EditType::NoOp,
621621
EditCommand::CutTextObject { .. } => EditType::EditText,
622622
EditCommand::CopyTextObject { .. } => EditType::NoOp,
623623
EditCommand::CopyFromStart
@@ -674,8 +674,8 @@ pub enum UndoBehavior {
674674
/// Catch-all for actions that should always form a unique undo point and never be
675675
/// grouped with later edits
676676
CreateUndoPoint,
677-
/// Undo/Redo actions shouldn't be reflected on the edit stack
678-
UndoRedo,
677+
/// For actions that shouldn't be reflected on the edit stack e.g. Undo/Redo
678+
NoOp,
679679
}
680680

681681
impl UndoBehavior {

0 commit comments

Comments
 (0)