Skip to content

Commit 902613a

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 d027940 commit 902613a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/core_editor/editor.rs

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

@@ -303,8 +303,8 @@ impl Editor {
303303
}
304304

305305
pub(crate) fn update_undo_state(&mut self, undo_behavior: UndoBehavior) {
306-
if matches!(undo_behavior, UndoBehavior::UndoRedo) {
307-
self.last_undo_behavior = UndoBehavior::UndoRedo;
306+
if matches!(undo_behavior, UndoBehavior::NoOp) {
307+
self.last_undo_behavior = UndoBehavior::NoOp;
308308
return;
309309
}
310310
if !undo_behavior.create_undo_point_after(&self.last_undo_behavior) {

src/enums.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl EditCommand {
547547
#[cfg(feature = "system_clipboard")]
548548
EditCommand::CopySelectionSystem => EditType::NoOp,
549549
EditCommand::CutInside { .. } => EditType::EditText,
550-
EditCommand::YankInside { .. } => EditType::EditText,
550+
EditCommand::YankInside { .. } => EditType::NoOp,
551551
EditCommand::CopyFromStart
552552
| EditCommand::CopyFromLineStart
553553
| EditCommand::CopyToEnd
@@ -602,8 +602,8 @@ pub enum UndoBehavior {
602602
/// Catch-all for actions that should always form a unique undo point and never be
603603
/// grouped with later edits
604604
CreateUndoPoint,
605-
/// Undo/Redo actions shouldn't be reflected on the edit stack
606-
UndoRedo,
605+
/// For actions that shouldn't be reflected on the edit stack e.g. Undo/Redo
606+
NoOp,
607607
}
608608

609609
impl UndoBehavior {

0 commit comments

Comments
 (0)