mirror of https://github.com/helix-editor/helix
fix: repeating repeat operator (#4450)
parent
9fae4b8118
commit
65edf9c198
|
@ -25,7 +25,7 @@ use helix_view::{
|
||||||
keyboard::{KeyCode, KeyModifiers},
|
keyboard::{KeyCode, KeyModifiers},
|
||||||
Document, Editor, Theme, View,
|
Document, Editor, Theme, View,
|
||||||
};
|
};
|
||||||
use std::{borrow::Cow, cmp::min, path::PathBuf};
|
use std::{borrow::Cow, cmp::min, num::NonZeroUsize, path::PathBuf};
|
||||||
|
|
||||||
use tui::buffer::Buffer as Surface;
|
use tui::buffer::Buffer as Surface;
|
||||||
|
|
||||||
|
@ -1009,37 +1009,40 @@ impl EditorView {
|
||||||
}
|
}
|
||||||
// special handling for repeat operator
|
// special handling for repeat operator
|
||||||
(key!('.'), _) if self.keymaps.pending().is_empty() => {
|
(key!('.'), _) if self.keymaps.pending().is_empty() => {
|
||||||
// first execute whatever put us into insert mode
|
for _ in 0..cxt.editor.count.map_or(1, NonZeroUsize::into) {
|
||||||
self.last_insert.0.execute(cxt);
|
// first execute whatever put us into insert mode
|
||||||
// then replay the inputs
|
self.last_insert.0.execute(cxt);
|
||||||
for key in self.last_insert.1.clone() {
|
// then replay the inputs
|
||||||
match key {
|
for key in self.last_insert.1.clone() {
|
||||||
InsertEvent::Key(key) => self.insert_mode(cxt, key),
|
match key {
|
||||||
InsertEvent::CompletionApply(compl) => {
|
InsertEvent::Key(key) => self.insert_mode(cxt, key),
|
||||||
let (view, doc) = current!(cxt.editor);
|
InsertEvent::CompletionApply(compl) => {
|
||||||
|
let (view, doc) = current!(cxt.editor);
|
||||||
|
|
||||||
doc.restore(view);
|
doc.restore(view);
|
||||||
|
|
||||||
let text = doc.text().slice(..);
|
let text = doc.text().slice(..);
|
||||||
let cursor = doc.selection(view.id).primary().cursor(text);
|
let cursor = doc.selection(view.id).primary().cursor(text);
|
||||||
|
|
||||||
let shift_position =
|
let shift_position =
|
||||||
|pos: usize| -> usize { pos + cursor - compl.trigger_offset };
|
|pos: usize| -> usize { pos + cursor - compl.trigger_offset };
|
||||||
|
|
||||||
let tx = Transaction::change(
|
let tx = Transaction::change(
|
||||||
doc.text(),
|
doc.text(),
|
||||||
compl.changes.iter().cloned().map(|(start, end, t)| {
|
compl.changes.iter().cloned().map(|(start, end, t)| {
|
||||||
(shift_position(start), shift_position(end), t)
|
(shift_position(start), shift_position(end), t)
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
apply_transaction(&tx, doc, view);
|
apply_transaction(&tx, doc, view);
|
||||||
}
|
}
|
||||||
InsertEvent::TriggerCompletion => {
|
InsertEvent::TriggerCompletion => {
|
||||||
let (_, doc) = current!(cxt.editor);
|
let (_, doc) = current!(cxt.editor);
|
||||||
doc.savepoint();
|
doc.savepoint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cxt.editor.count = None;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// set the count
|
// set the count
|
||||||
|
|
Loading…
Reference in New Issue