Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/vim/src/digraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Vim {
let text = lookup_digraph(first_char, second_char, cx);

self.pop_operator(window, cx);
if self.editor_input_enabled() {
if self.editor_input_enabled(cx) {
self.update_editor(cx, |_, editor, cx| editor.insert(&text, window, cx));
} else {
self.input_ignored(text, window, cx);
Expand Down Expand Up @@ -210,7 +210,7 @@ impl Vim {
}
text.push_str(suffix);

if self.editor_input_enabled() {
if self.editor_input_enabled(cx) {
self.update_editor(cx, |_, editor, cx| editor.insert(&text, window, cx));
} else {
self.input_ignored(text.into(), window, cx);
Expand Down
19 changes: 14 additions & 5 deletions crates/vim/src/mode_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,19 @@ impl Render for ModeIndicator {
return div().hidden().into_any_element();
};

let vim_readable = vim.read(cx);
let status_label = vim_readable.status_label.clone();
let temp_mode = vim_readable.temp_mode;
let mode = vim_readable.mode;
let (status_label, temp_mode, mode) = {
let vim_readable = vim.read(cx);
(
vim_readable.status_label.clone(),
vim_readable.temp_mode,
vim_readable.mode,
)
};

let vim_enabled = Vim::enabled(cx);
if !vim_enabled {
return div().hidden().into_any_element();
}

let theme = cx.theme();
let colors = theme.colors();
Expand All @@ -122,7 +131,7 @@ impl Render for ModeIndicator {
mode.to_string()
};

let current_operators_description = self.current_operators_description(vim.clone(), cx);
let current_operators_description = self.current_operators_description(vim, cx);
let pending = self
.pending_keys
.as_ref()
Expand Down
5 changes: 3 additions & 2 deletions crates/vim/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,14 @@ impl VimGlobals {

cx.observe_global::<SettingsStore>(move |cx| {
let is_enabled = Vim::enabled(cx);

KeyBinding::set_vim_mode(cx, is_enabled);

if was_enabled == Some(is_enabled) {
return;
}
was_enabled = Some(is_enabled);
if is_enabled {
KeyBinding::set_vim_mode(cx, true);
CommandPaletteFilter::update_global(cx, |filter, _| {
filter.show_namespace(Vim::NAMESPACE);
});
Expand All @@ -735,7 +737,6 @@ impl VimGlobals {
}
}
} else {
KeyBinding::set_vim_mode(cx, false);
*Vim::globals(cx) = VimGlobals::default();
GlobalCommandPaletteInterceptor::clear(cx);
CommandPaletteFilter::update_global(cx, |filter, _| {
Expand Down
75 changes: 73 additions & 2 deletions crates/vim/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ use gpui::{KeyBinding, Modifiers, MouseButton, TestAppContext, px};
use itertools::Itertools;
use language::{Language, LanguageConfig, Point};
pub use neovim_backed_test_context::*;
use settings::SettingsStore;
use settings::{ActionSequence, SettingsStore};
use ui::Pixels;
use util::test::marked_text_ranges;
pub use vim_test_context::*;

use indoc::indoc;
use search::BufferSearchBar;

use crate::{PushSneak, PushSneakBackward, insert::NormalBefore, motion, state::Mode};
use crate::{
PushDelete, PushFindForward, PushObject, PushSneak, PushSneakBackward, SwitchToVisualMode,
helix::HelixGotoLastModification, insert::NormalBefore, motion, object::AnyQuotes, state::Mode,
};

use util_macros::perf;

Expand Down Expand Up @@ -2322,6 +2325,74 @@ async fn test_clipping_on_mode_change(cx: &mut gpui::TestAppContext) {
);
}

#[gpui::test]
async fn test_vim_disabled_actions_work_with_manual_binding(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, false).await;

cx.update(|_, cx| {
cx.bind_keys([KeyBinding::new(
"ctrl-'",
ActionSequence(vec![
Box::new(SwitchToVisualMode {}),
Box::new(PushObject { around: false }),
Box::new(AnyQuotes {}),
]),
None,
)])
});

cx.simulate_keystrokes("l e t x = h e l l o w o r l d");
cx.set_state(r#"let x = "hello worldˇ";"#, Mode::Normal);
cx.simulate_keystrokes("ctrl-'");
cx.assert_state(r#"let x = "«hello worldˇ»";"#, Mode::Visual);
}

#[gpui::test]
async fn test_vim_disabled_multi_keystroke_sequence_works(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, false).await;

cx.update(|_, cx| {
cx.bind_keys([
KeyBinding::new("ctrl-d", PushDelete, None),
KeyBinding::new(
"ctrl-alt-t",
PushFindForward {
before: true,
multiline: true,
},
None,
),
])
});

cx.set_state("helloˇ world test", Mode::Normal);

// This should delete until the next space
cx.simulate_keystrokes("ctrl-d ctrl-alt-t space");
cx.assert_editor_state("helloˇ test");
}

#[gpui::test]
async fn test_vim_disabled_goto_last_modification(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, false).await;

cx.update(|_, cx| cx.bind_keys([KeyBinding::new("ctrl-g", HelixGotoLastModification, None)]));

cx.set_state("hello ˇworld", Mode::Normal);

// Create a modification
cx.simulate_keystrokes("z e d space");
cx.assert_editor_state("hello zed ˇworld");

// Move away
cx.simulate_keystrokes("up");
cx.assert_editor_state("ˇhello zed world");

// Go to last modification
cx.simulate_keystrokes("ctrl-g");
cx.assert_editor_state("hello zed ˇworld");
}

#[gpui::test]
async fn test_wrap_selections_in_tag_line_mode(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;
Expand Down
Loading