diff options
author | Pascal Kuthe | 2023-03-02 23:34:05 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2023-03-09 04:01:02 +0000 |
commit | aabc8af95dd1c093da4b67151f6a7026a85e9c0e (patch) | |
tree | bddf47edd063c70399ecfea80d9191f63ac400b2 /helix-term/src/commands.rs | |
parent | 8cb7cdfd7a01b9cb50b9142e9a5d133bd1e23256 (diff) |
correctly store snapshots when repeating insert-mode actions
Repeating completions currently crates a savepoint when a completion
popup was triggered (so after the request completed). Just like for
normal completions the savepoint must be created at the request.
The occurrence of the completion request was previously not saved in
`last_insert`. To that end a new `InsertEvent::RequestCompletion`
variant has been added. When replayed this event creates a snapshot
that is "actived" by the `TriggerCompletion` event and subsequently
used during any `InsertEvent::CompletiuonApply` events.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r-- | helix-term/src/commands.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 574e1edf..6817bc5c 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -53,7 +53,10 @@ use crate::{ filter_picker_entry, job::Callback, keymap::ReverseKeymap, - ui::{self, overlay::overlayed, FilePicker, Picker, Popup, Prompt, PromptEvent}, + ui::{ + self, editor::InsertEvent, overlay::overlayed, FilePicker, Picker, Popup, Prompt, + PromptEvent, + }, }; use crate::job::{self, Jobs}; @@ -4205,6 +4208,20 @@ pub fn completion(cx: &mut Context) { let trigger_doc = doc.id(); let trigger_view = view.id; + // FIXME: The commands Context can only have a single callback + // which means it gets overwritten when executing keybindings + // with multiple commands or macros. This would mean that completion + // might be incorrectly applied when repeating the insertmode action + // + // TODO: to solve this either make cx.callback a Vec of callbacks or + // alternatively move `last_insert` to `helix_view::Editor` + cx.callback = Some(Box::new( + move |compositor: &mut Compositor, _cx: &mut compositor::Context| { + let ui = compositor.find::<ui::EditorView>().unwrap(); + ui.last_insert.1.push(InsertEvent::RequestCompletion); + }, + )); + cx.callback( future, move |editor, compositor, response: Option<lsp::CompletionResponse>| { |