on master help sign in
save selection before completion savepoint
2588fa3Pascal Kuthe
helix-term/src/commands.rs+1−1
@@ -4181,7 +4181,7 @@ pub fn completion(cx: &mut Context) {
4181 iter.reverse();
4181 iter.reverse();
4182 let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count();
4182 let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count();
4183 let start_offset = cursor.saturating_sub(offset);
4183 let start_offset = cursor.saturating_sub(offset);
4184− doc.savepoint();
4184+ doc.savepoint(&view);
4185
4185
4186 cx.callback(
4186 cx.callback(
4187 future,
4187 future,
helix-term/src/ui/completion.rs+1−1
@@ -235,7 +235,7 @@ impl Completion {
235 );
235 );
236
236
237 // initialize a savepoint
237 // initialize a savepoint
238− doc.savepoint();
238+ doc.savepoint(&view);
239 doc.apply(&transaction, view.id);
239 doc.apply(&transaction, view.id);
240
240
241 editor.last_completion = Some(CompleteAction {
241 editor.last_completion = Some(CompleteAction {
helix-term/src/ui/editor.rs+2−2
@@ -914,8 +914,8 @@ impl EditorView {
914 doc.apply(&tx, view.id);
914 doc.apply(&tx, view.id);
915 }
915 }
916 InsertEvent::TriggerCompletion => {
916 InsertEvent::TriggerCompletion => {
917− let (_, doc) = current!(cxt.editor);
917+ let (view, doc) = current!(cxt.editor);
918− doc.savepoint();
918+ doc.savepoint(view);
919 }
919 }
920 }
920 }
921 }
921 }
helix-view/src/document.rs+2−1
@@ -941,7 +941,8 @@ impl Document {
941 }
941 }
942
942
943 pub fn savepoint(&mut self) {
943 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()));
945 }
946 }
946
947
947 pub fn restore(&mut self, view: &mut View) {
948 pub fn restore(&mut self, view: &mut View) {