diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.json index aa3e44892c..326555c3b9 100644 --- a/assets/keymaps/vim.json +++ b/assets/keymaps/vim.json @@ -694,5 +694,23 @@ "shift-x": "git::StageAll", "shift-u": "git::UnstageAll" } + }, + { + "context": "os == macos && edit_prediction", + "bindings": { + "alt-tab": "editor::AcceptEditPrediction" + } + }, + { + "context": "os != macos && edit_prediction", + "bindings": { + "alt-enter": "editor::AcceptEditPrediction" + } + }, + { + "context": "edit_prediction && !edit_prediction_requires_modifier", + "bindings": { + "tab": "editor::AcceptEditPrediction" + } } ] diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 5ae3c82dbf..43a3b6acad 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -48,7 +48,7 @@ mod signature_help; pub mod test; pub(crate) use actions::*; -pub use actions::{OpenExcerpts, OpenExcerptsSplit}; +pub use actions::{AcceptEditPrediction, OpenExcerpts, OpenExcerptsSplit}; use aho_corasick::AhoCorasick; use anyhow::{anyhow, Context as _, Result}; use blink_manager::BlinkManager; @@ -1940,15 +1940,6 @@ impl Editor { self.refresh_inline_completion(false, true, window, cx); } - pub fn inline_completion_start_anchor(&self) -> Option { - let active_completion = self.active_inline_completion.as_ref()?; - let result = match &active_completion.completion { - InlineCompletion::Edit { edits, .. } => edits.first()?.0.start, - InlineCompletion::Move { target, .. } => *target, - }; - Some(result) - } - fn inline_completions_disabled_in_scope( &self, buffer: &Entity, diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index a3a3afc443..05cfc00bfd 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -23,7 +23,6 @@ use anyhow::Result; use collections::HashMap; use editor::{ movement::{self, FindRange}, - scroll::Autoscroll, Anchor, Bias, Editor, EditorEvent, EditorMode, ToPoint, }; use gpui::{ @@ -649,20 +648,24 @@ impl Vim { vim.push_count_digit(n.0, window, cx); }); Vim::action(editor, cx, |vim, _: &Tab, window, cx| { - let Some(anchor) = vim - .editor() - .and_then(|editor| editor.read(cx).inline_completion_start_anchor()) - else { - return; - }; - - vim.update_editor(window, cx, |_, editor, window, cx| { - editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { - s.select_anchor_ranges([anchor..anchor]) - }); - }); - vim.switch_mode(Mode::Insert, true, window, cx); + vim.input_ignored(" ".into(), window, cx) }); + Vim::action( + editor, + cx, + |vim, action: &editor::AcceptEditPrediction, window, cx| { + vim.update_editor(window, cx, |_, editor, window, cx| { + editor.accept_edit_prediction(action, window, cx); + }); + // In non-insertion modes, predictions will be hidden and instead a jump will be + // displayed (and performed by `accept_edit_prediction`). This switches to + // insert mode so that the prediction is displayed after the jump. + match vim.mode { + Mode::Replace => {} + _ => vim.switch_mode(Mode::Insert, true, window, cx), + }; + }, + ); Vim::action(editor, cx, |vim, _: &Enter, window, cx| { vim.input_ignored("\n".into(), window, cx) });