Skip to content

Commit f2d0522

Browse files
committed
simplify LastCutCommand variants, add comments
1 parent a138694 commit f2d0522

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/core_editor/editor.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ use crate::{core_editor::get_default_clipboard, EditCommand};
66

77
// Determines how we update the cut buffer when we next cut
88
enum LastCutCommand {
9-
// We are currently
10-
ThisCommand,
11-
LastCommand,
12-
BeforeLastCommand,
9+
// We are currently running a command that includes a cut command.
10+
This,
11+
// We have just run a command that includes a cut command.
12+
Last,
13+
// We have not recently run a cut command. Replace the cut buffer if another cut happens.
14+
BeforeLast,
1315
}
1416

1517
// Which direction are we cutting in?
@@ -36,7 +38,7 @@ impl Default for Editor {
3638
Editor {
3739
line_buffer: LineBuffer::new(),
3840
cut_buffer: Box::new(get_default_clipboard()),
39-
last_cut_command: LastCutCommand::BeforeLastCommand,
41+
last_cut_command: LastCutCommand::BeforeLast,
4042
edit_stack: EditStack::new(),
4143
last_undo_behavior: UndoBehavior::CreateUndoPoint,
4244
}
@@ -117,10 +119,8 @@ impl Editor {
117119
}
118120

119121
self.last_cut_command = match self.last_cut_command {
120-
LastCutCommand::ThisCommand => LastCutCommand::LastCommand,
121-
LastCutCommand::LastCommand | LastCutCommand::BeforeLastCommand => {
122-
LastCutCommand::BeforeLastCommand
123-
}
122+
LastCutCommand::This => LastCutCommand::Last,
123+
LastCutCommand::Last | LastCutCommand::BeforeLast => LastCutCommand::BeforeLast,
124124
};
125125

126126
let new_undo_behavior = match (command, command.edit_type()) {
@@ -249,7 +249,7 @@ impl Editor {
249249
// Otherwise, replace what's in the cut buffer.
250250
let buf;
251251
let cut_slice = match (&self.last_cut_command, direction) {
252-
(LastCutCommand::BeforeLastCommand, _) => cut_slice,
252+
(LastCutCommand::BeforeLast, _) => cut_slice,
253253
(_, CutDirection::Left) => {
254254
let existing = self.cut_buffer.get().0;
255255
buf = format!("{cut_slice}{existing}");
@@ -272,7 +272,7 @@ impl Editor {
272272
self.line_buffer.set_insertion_point(start);
273273
self.line_buffer.clear_range(cut_range);
274274
}
275-
self.last_cut_command = LastCutCommand::ThisCommand;
275+
self.last_cut_command = LastCutCommand::This;
276276
}
277277

278278
fn cut_current_line(&mut self) {

0 commit comments

Comments
 (0)