save selection before completion savepoint
Currently, the selection is not saved/restored when completion
checkpoints are applied. This is usually fine because undoing changes
usually restores maps selections back in insert mode. But this is not
always the case and especially problematic in the presence of
multi-cursor completions (since completions are applied relative to
the selection/cursor) and snippets (which can change the selection)
commit2588fa3710921683c16a84ffd91103a0823a033b
authorPascal Kuthe <pascal.kuthe@semimod.de>
dateThu 2 Mar 2023, 19:10 (4 years ago)
parent4300a3a
helix-term/src/commands.rs+1−1
@@ -4181,7 +4181,7 @@ pub fn completion(cx: &mut Context) {
41814181 iter.reverse();
41824182 let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count();
41834183 let start_offset = cursor.saturating_sub(offset);
4184− doc.savepoint();
4184+ doc.savepoint(&view);
41854185
41864186 cx.callback(
41874187 future,
helix-term/src/ui/completion.rs+1−1
@@ -235,7 +235,7 @@ impl Completion {
235235 );
236236
237237 // initialize a savepoint
238− doc.savepoint();
238+ doc.savepoint(&view);
239239 doc.apply(&transaction, view.id);
240240
241241 editor.last_completion = Some(CompleteAction {
helix-term/src/ui/editor.rs+2−2
@@ -914,8 +914,8 @@ impl EditorView {
914914 doc.apply(&tx, view.id);
915915 }
916916 InsertEvent::TriggerCompletion => {
917− let (_, doc) = current!(cxt.editor);
918− doc.savepoint();
917+ let (view, doc) = current!(cxt.editor);
918+ doc.savepoint(view);
919919 }
920920 }
921921 }
helix-view/src/document.rs+2−1
@@ -941,7 +941,8 @@ impl Document {
941941 }
942942
943943 pub fn savepoint(&mut self) {
944− self.savepoint = Some(Transaction::new(self.text()));
944+ self.savepoint =
945+ Some(Transaction::new(self.text()).with_selection(self.selection(view.id).clone()));
945946 }
946947
947948 pub fn restore(&mut self, view: &mut View) {