Skip to content

Commit 23acfdc

Browse files
kosciejShekhinah Memmel
authored andcommitted
fix: repeating repeat operator (helix-editor#4450)
1 parent 21d6acf commit 23acfdc

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
@@ -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

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

0 commit comments

Comments
 (0)