Skip to content

Commit 65edf9c

Browse files
authored
fix: repeating repeat operator (#4450)
1 parent 9fae4b8 commit 65edf9c

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

helix-term/src/ui/editor.rs

+32-29
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use helix_view::{
2525
keyboard::{KeyCode, KeyModifiers},
2626
Document, Editor, Theme, View,
2727
};
28-
use std::{borrow::Cow, cmp::min, path::PathBuf};
28+
use std::{borrow::Cow, cmp::min, num::NonZeroUsize, path::PathBuf};
2929

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

@@ -1009,37 +1009,40 @@ impl EditorView {
10091009
}
10101010
// special handling for repeat operator
10111011
(key!('.'), _) if self.keymaps.pending().is_empty() => {
1012-
// first execute whatever put us into insert mode
1013-
self.last_insert.0.execute(cxt);
1014-
// then replay the inputs
1015-
for key in self.last_insert.1.clone() {
1016-
match key {
1017-
InsertEvent::Key(key) => self.insert_mode(cxt, key),
1018-
InsertEvent::CompletionApply(compl) => {
1019-
let (view, doc) = current!(cxt.editor);
1020-
1021-
doc.restore(view);
1022-
1023-
let text = doc.text().slice(..);
1024-
let cursor = doc.selection(view.id).primary().cursor(text);
1025-
1026-
let shift_position =
1027-
|pos: usize| -> usize { pos + cursor - compl.trigger_offset };
1028-
1029-
let tx = Transaction::change(
1030-
doc.text(),
1031-
compl.changes.iter().cloned().map(|(start, end, t)| {
1032-
(shift_position(start), shift_position(end), t)
1033-
}),
1034-
);
1035-
apply_transaction(&tx, doc, view);
1036-
}
1037-
InsertEvent::TriggerCompletion => {
1038-
let (_, doc) = current!(cxt.editor);
1039-
doc.savepoint();
1012+
for _ in 0..cxt.editor.count.map_or(1, NonZeroUsize::into) {
1013+
// first execute whatever put us into insert mode
1014+
self.last_insert.0.execute(cxt);
1015+
// then replay the inputs
1016+
for key in self.last_insert.1.clone() {
1017+
match key {
1018+
InsertEvent::Key(key) => self.insert_mode(cxt, key),
1019+
InsertEvent::CompletionApply(compl) => {
1020+
let (view, doc) = current!(cxt.editor);
1021+
1022+
doc.restore(view);
1023+
1024+
let text = doc.text().slice(..);
1025+
let cursor = doc.selection(view.id).primary().cursor(text);
1026+
1027+
let shift_position =
1028+
|pos: usize| -> usize { pos + cursor - compl.trigger_offset };
1029+
1030+
let tx = Transaction::change(
1031+
doc.text(),
1032+
compl.changes.iter().cloned().map(|(start, end, t)| {
1033+
(shift_position(start), shift_position(end), t)
1034+
}),
1035+
);
1036+
apply_transaction(&tx, doc, view);
1037+
}
1038+
InsertEvent::TriggerCompletion => {
1039+
let (_, doc) = current!(cxt.editor);
1040+
doc.savepoint();
1041+
}
10401042
}
10411043
}
10421044
}
1045+
cxt.editor.count = None;
10431046
}
10441047
_ => {
10451048
// set the count

0 commit comments

Comments
 (0)