mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-25 02:46:17 +04:00
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)
This commit is contained in:
parent
4300a3ad05
commit
2588fa3710
@ -4181,7 +4181,7 @@ pub fn completion(cx: &mut Context) {
|
||||
iter.reverse();
|
||||
let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count();
|
||||
let start_offset = cursor.saturating_sub(offset);
|
||||
doc.savepoint();
|
||||
doc.savepoint(&view);
|
||||
|
||||
cx.callback(
|
||||
future,
|
||||
|
@ -235,7 +235,7 @@ fn completion_changes(transaction: &Transaction, trigger_offset: usize) -> Vec<C
|
||||
);
|
||||
|
||||
// initialize a savepoint
|
||||
doc.savepoint();
|
||||
doc.savepoint(&view);
|
||||
doc.apply(&transaction, view.id);
|
||||
|
||||
editor.last_completion = Some(CompleteAction {
|
||||
|
@ -914,8 +914,8 @@ fn command_mode(&mut self, mode: Mode, cxt: &mut commands::Context, event: KeyEv
|
||||
doc.apply(&tx, view.id);
|
||||
}
|
||||
InsertEvent::TriggerCompletion => {
|
||||
let (_, doc) = current!(cxt.editor);
|
||||
doc.savepoint();
|
||||
let (view, doc) = current!(cxt.editor);
|
||||
doc.savepoint(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -941,7 +941,8 @@ pub fn redo(&mut self, view: &mut View) -> bool {
|
||||
}
|
||||
|
||||
pub fn savepoint(&mut self) {
|
||||
self.savepoint = Some(Transaction::new(self.text()));
|
||||
self.savepoint =
|
||||
Some(Transaction::new(self.text()).with_selection(self.selection(view.id).clone()));
|
||||
}
|
||||
|
||||
pub fn restore(&mut self, view: &mut View) {
|
||||
|
Loading…
Reference in New Issue
Block a user