Skip to content

Commit 5d84674

Browse files
kosciejpathwave
authored andcommitted
fix: repeating repeat operator (helix-editor#4450)
1 parent 36db8d1 commit 5d84674

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

helix-term/src/ui/editor.rs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use helix_view::{
2626
keyboard::{KeyCode, KeyModifiers},
2727
Document, Editor, Theme, View,
2828
};
29-
use std::{borrow::Cow, path::PathBuf};
29+
use std::{borrow::Cow, cmp::min, num::NonZeroUsize, path::PathBuf};
3030

3131
use tui::buffer::Buffer as Surface;
3232

@@ -1056,37 +1056,40 @@ impl EditorView {
10561056
}
10571057
// special handling for repeat operator
10581058
(key!('.'), _) if self.keymaps.pending().is_empty() => {
1059-
// first execute whatever put us into insert mode
1060-
self.last_insert.0.execute(cxt);
1061-
// then replay the inputs
1062-
for key in self.last_insert.1.clone() {
1063-
match key {
1064-
InsertEvent::Key(key) => self.insert_mode(cxt, key),
1065-
InsertEvent::CompletionApply(compl) => {
1066-
let (view, doc) = current!(cxt.editor);
1067-
1068-
doc.restore(view);
1069-
1070-
let text = doc.text().slice(..);
1071-
let cursor = doc.selection(view.id).primary().cursor(text);
1072-
1073-
let shift_position =
1074-
|pos: usize| -> usize { pos + cursor - compl.trigger_offset };
1075-
1076-
let tx = Transaction::change(
1077-
doc.text(),
1078-
compl.changes.iter().cloned().map(|(start, end, t)| {
1079-
(shift_position(start), shift_position(end), t)
1080-
}),
1081-
);
1082-
apply_transaction(&tx, doc, view);
1083-
}
1084-
InsertEvent::TriggerCompletion => {
1085-
let (_, doc) = current!(cxt.editor);
1086-
doc.savepoint();
1059+
for _ in 0..cxt.editor.count.map_or(1, NonZeroUsize::into) {
1060+
// first execute whatever put us into insert mode
1061+
self.last_insert.0.execute(cxt);
1062+
// then replay the inputs
1063+
for key in self.last_insert.1.clone() {
1064+
match key {
1065+
InsertEvent::Key(key) => self.insert_mode(cxt, key),
1066+
InsertEvent::CompletionApply(compl) => {
1067+
let (view, doc) = current!(cxt.editor);
1068+
1069+
doc.restore(view);
1070+
1071+
let text = doc.text().slice(..);
1072+
let cursor = doc.selection(view.id).primary().cursor(text);
1073+
1074+
let shift_position =
1075+
|pos: usize| -> usize { pos + cursor - compl.trigger_offset };
1076+
1077+
let tx = Transaction::change(
1078+
doc.text(),
1079+
compl.changes.iter().cloned().map(|(start, end, t)| {
1080+
(shift_position(start), shift_position(end), t)
1081+
}),
1082+
);
1083+
apply_transaction(&tx, doc, view);
1084+
}
1085+
InsertEvent::TriggerCompletion => {
1086+
let (_, doc) = current!(cxt.editor);
1087+
doc.savepoint();
1088+
}
10871089
}
10881090
}
10891091
}
1092+
cxt.editor.count = None;
10901093
}
10911094
_ => {
10921095
// set the count

0 commit comments

Comments
 (0)