2022-04-21 23:14:58 +00:00
|
|
|
#[cfg(test)]
|
2022-10-10 21:46:07 +00:00
|
|
|
mod test;
|
2022-04-21 23:14:58 +00:00
|
|
|
|
2022-03-25 02:24:36 +00:00
|
|
|
mod editor_events;
|
|
|
|
mod insert;
|
2023-07-20 18:32:27 +00:00
|
|
|
mod mode_indicator;
|
2022-04-15 23:00:44 +00:00
|
|
|
mod motion;
|
2022-03-25 02:24:36 +00:00
|
|
|
mod normal;
|
2022-10-06 03:19:30 +00:00
|
|
|
mod object;
|
2022-04-15 23:00:44 +00:00
|
|
|
mod state;
|
2022-05-20 00:42:30 +00:00
|
|
|
mod utils;
|
2022-05-03 17:29:57 +00:00
|
|
|
mod visual;
|
2022-03-25 02:24:36 +00:00
|
|
|
|
2023-05-11 21:40:35 +00:00
|
|
|
use anyhow::Result;
|
2023-03-29 03:13:17 +00:00
|
|
|
use collections::CommandPaletteFilter;
|
2023-07-03 21:20:10 +00:00
|
|
|
use editor::{Bias, Editor, EditorMode, Event};
|
2023-01-09 23:44:40 +00:00
|
|
|
use gpui::{
|
2023-07-20 21:22:15 +00:00
|
|
|
actions, impl_actions, keymap_matcher::KeymapContext, keymap_matcher::MatchResult, AppContext,
|
|
|
|
Subscription, ViewContext, ViewHandle, WeakViewHandle, WindowContext,
|
2023-01-09 23:44:40 +00:00
|
|
|
};
|
2022-10-15 22:08:21 +00:00
|
|
|
use language::CursorShape;
|
2023-07-20 18:32:27 +00:00
|
|
|
pub use mode_indicator::ModeIndicator;
|
2023-01-09 23:44:40 +00:00
|
|
|
use motion::Motion;
|
|
|
|
use normal::normal_replace;
|
2022-04-08 22:32:56 +00:00
|
|
|
use serde::Deserialize;
|
2023-05-10 18:06:55 +00:00
|
|
|
use settings::{Setting, SettingsStore};
|
2022-04-15 23:00:44 +00:00
|
|
|
use state::{Mode, Operator, VimState};
|
2023-05-11 21:40:35 +00:00
|
|
|
use std::sync::Arc;
|
2023-01-09 23:44:40 +00:00
|
|
|
use visual::visual_replace;
|
2022-04-06 00:10:17 +00:00
|
|
|
use workspace::{self, Workspace};
|
2022-03-25 02:24:36 +00:00
|
|
|
|
2023-05-10 18:06:55 +00:00
|
|
|
struct VimModeSetting(bool);
|
|
|
|
|
2022-06-06 07:18:44 +00:00
|
|
|
#[derive(Clone, Deserialize, PartialEq)]
|
2022-04-07 23:20:49 +00:00
|
|
|
pub struct SwitchMode(pub Mode);
|
|
|
|
|
2022-06-06 07:18:44 +00:00
|
|
|
#[derive(Clone, Deserialize, PartialEq)]
|
2022-04-15 23:00:44 +00:00
|
|
|
pub struct PushOperator(pub Operator);
|
|
|
|
|
2022-10-09 04:20:47 +00:00
|
|
|
#[derive(Clone, Deserialize, PartialEq)]
|
|
|
|
struct Number(u8);
|
|
|
|
|
2023-02-10 23:41:19 +00:00
|
|
|
actions!(vim, [Tab, Enter]);
|
2022-10-09 04:20:47 +00:00
|
|
|
impl_actions!(vim, [Number, SwitchMode, PushOperator]);
|
2022-03-25 02:24:36 +00:00
|
|
|
|
2023-07-27 22:27:36 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
enum VimEvent {
|
|
|
|
ModeChanged { mode: Mode },
|
|
|
|
}
|
|
|
|
|
2023-04-06 21:49:03 +00:00
|
|
|
pub fn init(cx: &mut AppContext) {
|
2023-05-17 22:06:11 +00:00
|
|
|
settings::register::<VimModeSetting>(cx);
|
2023-05-10 18:06:55 +00:00
|
|
|
|
2022-03-25 02:24:36 +00:00
|
|
|
editor_events::init(cx);
|
2022-04-21 23:14:58 +00:00
|
|
|
normal::init(cx);
|
2022-05-03 17:29:57 +00:00
|
|
|
visual::init(cx);
|
2022-03-25 02:24:36 +00:00
|
|
|
insert::init(cx);
|
2022-10-06 03:19:30 +00:00
|
|
|
object::init(cx);
|
2022-04-15 23:00:44 +00:00
|
|
|
motion::init(cx);
|
2022-03-25 02:24:36 +00:00
|
|
|
|
2022-06-30 19:32:53 +00:00
|
|
|
// Vim Actions
|
2022-04-15 23:00:44 +00:00
|
|
|
cx.add_action(|_: &mut Workspace, &SwitchMode(mode): &SwitchMode, cx| {
|
2022-07-18 20:33:55 +00:00
|
|
|
Vim::update(cx, |vim, cx| vim.switch_mode(mode, false, cx))
|
2022-03-26 20:30:55 +00:00
|
|
|
});
|
2022-04-15 23:00:44 +00:00
|
|
|
cx.add_action(
|
|
|
|
|_: &mut Workspace, &PushOperator(operator): &PushOperator, cx| {
|
|
|
|
Vim::update(cx, |vim, cx| vim.push_operator(operator, cx))
|
|
|
|
},
|
|
|
|
);
|
2022-10-09 04:20:47 +00:00
|
|
|
cx.add_action(|_: &mut Workspace, n: &Number, cx: _| {
|
|
|
|
Vim::update(cx, |vim, cx| vim.push_number(n, cx));
|
|
|
|
});
|
2022-06-30 19:32:53 +00:00
|
|
|
|
2023-02-10 23:41:19 +00:00
|
|
|
cx.add_action(|_: &mut Workspace, _: &Tab, cx| {
|
|
|
|
Vim::active_editor_input_ignored(" ".into(), cx)
|
|
|
|
});
|
|
|
|
|
|
|
|
cx.add_action(|_: &mut Workspace, _: &Enter, cx| {
|
|
|
|
Vim::active_editor_input_ignored("\n".into(), cx)
|
|
|
|
});
|
|
|
|
|
2023-05-04 12:52:34 +00:00
|
|
|
// Any time settings change, update vim mode to match. The Vim struct
|
|
|
|
// will be initialized as disabled by default, so we filter its commands
|
|
|
|
// out when starting up.
|
|
|
|
cx.update_default_global::<CommandPaletteFilter, _, _>(|filter, _| {
|
|
|
|
filter.filtered_namespaces.insert("vim");
|
|
|
|
});
|
2023-04-20 15:29:14 +00:00
|
|
|
cx.update_default_global(|vim: &mut Vim, cx: &mut AppContext| {
|
2023-05-17 22:05:20 +00:00
|
|
|
vim.set_enabled(settings::get::<VimModeSetting>(cx).0, cx)
|
2023-04-20 15:29:14 +00:00
|
|
|
});
|
2023-05-10 18:06:55 +00:00
|
|
|
cx.observe_global::<SettingsStore, _>(|cx| {
|
2023-04-20 15:29:14 +00:00
|
|
|
cx.update_default_global(|vim: &mut Vim, cx: &mut AppContext| {
|
2023-05-17 22:05:20 +00:00
|
|
|
vim.set_enabled(settings::get::<VimModeSetting>(cx).0, cx)
|
2023-04-20 15:29:14 +00:00
|
|
|
});
|
2022-03-26 20:30:55 +00:00
|
|
|
})
|
|
|
|
.detach();
|
2022-03-25 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 09:56:31 +00:00
|
|
|
pub fn observe_keystrokes(cx: &mut WindowContext) {
|
2023-07-20 00:54:29 +00:00
|
|
|
cx.observe_keystrokes(|_keystroke, result, handled_by, cx| {
|
|
|
|
if result == &MatchResult::Pending {
|
|
|
|
return true;
|
|
|
|
}
|
2022-12-08 00:39:32 +00:00
|
|
|
if let Some(handled_by) = handled_by {
|
2023-01-06 22:03:01 +00:00
|
|
|
// Keystroke is handled by the vim system, so continue forward
|
2023-07-03 21:20:10 +00:00
|
|
|
if handled_by.namespace() == "vim" {
|
2022-12-08 00:39:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-10 22:41:22 +00:00
|
|
|
Vim::update(cx, |vim, cx| match vim.active_operator() {
|
2023-02-10 23:41:19 +00:00
|
|
|
Some(
|
|
|
|
Operator::FindForward { .. } | Operator::FindBackward { .. } | Operator::Replace,
|
|
|
|
) => {}
|
2023-02-10 22:41:22 +00:00
|
|
|
Some(_) => {
|
2022-12-08 00:39:32 +00:00
|
|
|
vim.clear_operator(cx);
|
|
|
|
}
|
2023-02-10 22:41:22 +00:00
|
|
|
_ => {}
|
2022-12-08 00:39:32 +00:00
|
|
|
});
|
|
|
|
true
|
|
|
|
})
|
|
|
|
.detach()
|
|
|
|
}
|
|
|
|
|
2022-03-25 02:24:36 +00:00
|
|
|
#[derive(Default)]
|
2022-04-15 23:00:44 +00:00
|
|
|
pub struct Vim {
|
2022-03-25 02:24:36 +00:00
|
|
|
active_editor: Option<WeakViewHandle<Editor>>,
|
2023-02-08 23:01:42 +00:00
|
|
|
editor_subscription: Option<Subscription>,
|
2022-03-25 02:24:36 +00:00
|
|
|
enabled: bool,
|
2022-04-15 23:00:44 +00:00
|
|
|
state: VimState,
|
2022-03-25 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2022-04-15 23:00:44 +00:00
|
|
|
impl Vim {
|
2023-04-06 21:49:03 +00:00
|
|
|
fn read(cx: &mut AppContext) -> &Self {
|
2022-04-15 23:00:44 +00:00
|
|
|
cx.default_global()
|
|
|
|
}
|
|
|
|
|
2023-04-20 15:29:14 +00:00
|
|
|
fn update<F, S>(cx: &mut WindowContext, update: F) -> S
|
2022-03-26 20:30:55 +00:00
|
|
|
where
|
2023-04-20 15:29:14 +00:00
|
|
|
F: FnOnce(&mut Self, &mut WindowContext) -> S,
|
2022-03-26 20:30:55 +00:00
|
|
|
{
|
|
|
|
cx.update_default_global(update)
|
|
|
|
}
|
|
|
|
|
2023-04-20 21:25:11 +00:00
|
|
|
fn set_active_editor(&mut self, editor: ViewHandle<Editor>, cx: &mut WindowContext) {
|
|
|
|
self.active_editor = Some(editor.downgrade());
|
|
|
|
self.editor_subscription = Some(cx.subscribe(&editor, |editor, event, cx| match event {
|
|
|
|
Event::SelectionsChanged { local: true } => {
|
|
|
|
let editor = editor.read(cx);
|
|
|
|
if editor.leader_replica_id().is_none() {
|
|
|
|
let newest_empty = editor.selections.newest::<usize>(cx).is_empty();
|
|
|
|
local_selections_changed(newest_empty, cx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Event::InputIgnored { text } => {
|
|
|
|
Vim::active_editor_input_ignored(text.clone(), cx);
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}));
|
|
|
|
|
|
|
|
if self.enabled {
|
|
|
|
let editor = editor.read(cx);
|
|
|
|
let editor_mode = editor.mode();
|
|
|
|
let newest_selection_empty = editor.selections.newest::<usize>(cx).is_empty();
|
|
|
|
|
|
|
|
if editor_mode == EditorMode::Full && !newest_selection_empty {
|
|
|
|
self.switch_mode(Mode::Visual { line: false }, true, cx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.sync_vim_settings(cx);
|
|
|
|
}
|
|
|
|
|
2022-03-25 02:24:36 +00:00
|
|
|
fn update_active_editor<S>(
|
2022-03-26 20:30:55 +00:00
|
|
|
&self,
|
2023-04-20 15:29:14 +00:00
|
|
|
cx: &mut WindowContext,
|
2022-03-25 02:24:36 +00:00
|
|
|
update: impl FnOnce(&mut Editor, &mut ViewContext<Editor>) -> S,
|
|
|
|
) -> Option<S> {
|
2023-04-17 09:17:35 +00:00
|
|
|
let editor = self.active_editor.clone()?.upgrade(cx)?;
|
2023-04-20 15:29:14 +00:00
|
|
|
Some(editor.update(cx, update))
|
2022-03-25 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 15:29:14 +00:00
|
|
|
fn switch_mode(&mut self, mode: Mode, leave_selections: bool, cx: &mut WindowContext) {
|
2022-04-15 23:00:44 +00:00
|
|
|
self.state.mode = mode;
|
|
|
|
self.state.operator_stack.clear();
|
2022-06-30 19:32:53 +00:00
|
|
|
|
2023-07-27 22:27:36 +00:00
|
|
|
cx.emit_global(VimEvent::ModeChanged { mode });
|
2023-07-24 15:37:48 +00:00
|
|
|
|
2022-06-30 19:32:53 +00:00
|
|
|
// Sync editor settings like clip mode
|
2022-06-29 18:58:12 +00:00
|
|
|
self.sync_vim_settings(cx);
|
2022-06-30 19:32:53 +00:00
|
|
|
|
2022-07-18 20:33:55 +00:00
|
|
|
if leave_selections {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-30 19:32:53 +00:00
|
|
|
// Adjust selections
|
2023-04-17 09:17:35 +00:00
|
|
|
self.update_active_editor(cx, |editor, cx| {
|
|
|
|
editor.change_selections(None, cx, |s| {
|
|
|
|
s.move_with(|map, selection| {
|
|
|
|
if self.state.empty_selections_only() {
|
|
|
|
let new_head = map.clip_point(selection.head(), Bias::Left);
|
|
|
|
selection.collapse_to(new_head, selection.goal)
|
|
|
|
} else {
|
|
|
|
selection
|
|
|
|
.set_head(map.clip_point(selection.head(), Bias::Left), selection.goal);
|
|
|
|
}
|
|
|
|
});
|
2023-02-08 23:01:42 +00:00
|
|
|
})
|
2023-04-17 09:17:35 +00:00
|
|
|
});
|
2022-03-25 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 15:29:14 +00:00
|
|
|
fn push_operator(&mut self, operator: Operator, cx: &mut WindowContext) {
|
2022-04-15 23:00:44 +00:00
|
|
|
self.state.operator_stack.push(operator);
|
2022-06-29 18:58:12 +00:00
|
|
|
self.sync_vim_settings(cx);
|
2022-04-15 23:00:44 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 15:29:14 +00:00
|
|
|
fn push_number(&mut self, Number(number): &Number, cx: &mut WindowContext) {
|
2022-10-09 04:20:47 +00:00
|
|
|
if let Some(Operator::Number(current_number)) = self.active_operator() {
|
|
|
|
self.pop_operator(cx);
|
|
|
|
self.push_operator(Operator::Number(current_number * 10 + *number as usize), cx);
|
|
|
|
} else {
|
|
|
|
self.push_operator(Operator::Number(*number as usize), cx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-20 15:29:14 +00:00
|
|
|
fn pop_operator(&mut self, cx: &mut WindowContext) -> Operator {
|
2022-10-06 03:19:30 +00:00
|
|
|
let popped_operator = self.state.operator_stack.pop()
|
|
|
|
.expect("Operator popped when no operator was on the stack. This likely means there is an invalid keymap config");
|
2022-06-29 18:58:12 +00:00
|
|
|
self.sync_vim_settings(cx);
|
2022-04-15 23:00:44 +00:00
|
|
|
popped_operator
|
|
|
|
}
|
|
|
|
|
2023-06-22 04:36:48 +00:00
|
|
|
fn pop_number_operator(&mut self, cx: &mut WindowContext) -> Option<usize> {
|
2022-10-09 04:20:47 +00:00
|
|
|
if let Some(Operator::Number(number)) = self.active_operator() {
|
|
|
|
self.pop_operator(cx);
|
2023-06-22 04:36:48 +00:00
|
|
|
return Some(number);
|
2022-10-09 04:20:47 +00:00
|
|
|
}
|
2023-06-22 04:36:48 +00:00
|
|
|
None
|
2022-10-09 04:20:47 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 15:29:14 +00:00
|
|
|
fn clear_operator(&mut self, cx: &mut WindowContext) {
|
2022-04-15 23:00:44 +00:00
|
|
|
self.state.operator_stack.clear();
|
2022-06-29 18:58:12 +00:00
|
|
|
self.sync_vim_settings(cx);
|
2022-04-15 23:00:44 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 18:04:26 +00:00
|
|
|
fn active_operator(&self) -> Option<Operator> {
|
2022-04-15 23:00:44 +00:00
|
|
|
self.state.operator_stack.last().copied()
|
|
|
|
}
|
|
|
|
|
2023-04-20 15:29:14 +00:00
|
|
|
fn active_editor_input_ignored(text: Arc<str>, cx: &mut WindowContext) {
|
2023-02-10 22:41:22 +00:00
|
|
|
if text.is_empty() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-09 23:44:40 +00:00
|
|
|
match Vim::read(cx).active_operator() {
|
|
|
|
Some(Operator::FindForward { before }) => {
|
2023-07-20 21:22:15 +00:00
|
|
|
let find = Motion::FindForward { before, text };
|
|
|
|
Vim::update(cx, |vim, _| vim.state.last_find = Some(find.clone()));
|
|
|
|
motion::motion(find, cx)
|
2023-01-09 23:44:40 +00:00
|
|
|
}
|
|
|
|
Some(Operator::FindBackward { after }) => {
|
2023-07-20 21:22:15 +00:00
|
|
|
let find = Motion::FindBackward { after, text };
|
|
|
|
Vim::update(cx, |vim, _| vim.state.last_find = Some(find.clone()));
|
|
|
|
motion::motion(find, cx)
|
2023-01-09 23:44:40 +00:00
|
|
|
}
|
|
|
|
Some(Operator::Replace) => match Vim::read(cx).state.mode {
|
2023-02-10 22:41:22 +00:00
|
|
|
Mode::Normal => normal_replace(text, cx),
|
|
|
|
Mode::Visual { line } => visual_replace(text, line, cx),
|
2023-01-09 23:44:40 +00:00
|
|
|
_ => Vim::update(cx, |vim, cx| vim.clear_operator(cx)),
|
|
|
|
},
|
2023-02-10 22:41:22 +00:00
|
|
|
_ => {}
|
2023-01-09 23:44:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-06 21:49:03 +00:00
|
|
|
fn set_enabled(&mut self, enabled: bool, cx: &mut AppContext) {
|
2022-03-26 20:30:55 +00:00
|
|
|
if self.enabled != enabled {
|
|
|
|
self.enabled = enabled;
|
2022-04-15 23:00:44 +00:00
|
|
|
self.state = Default::default();
|
2023-04-20 15:29:14 +00:00
|
|
|
|
|
|
|
cx.update_default_global::<CommandPaletteFilter, _, _>(|filter, _| {
|
|
|
|
if self.enabled {
|
|
|
|
filter.filtered_namespaces.remove("vim");
|
|
|
|
} else {
|
|
|
|
filter.filtered_namespaces.insert("vim");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
cx.update_active_window(|cx| {
|
|
|
|
if self.enabled {
|
2023-04-20 21:25:11 +00:00
|
|
|
let active_editor = cx
|
2023-04-20 15:29:14 +00:00
|
|
|
.root_view()
|
|
|
|
.downcast_ref::<Workspace>()
|
|
|
|
.and_then(|workspace| workspace.read(cx).active_item(cx))
|
2023-04-20 21:25:11 +00:00
|
|
|
.and_then(|item| item.downcast::<Editor>());
|
|
|
|
if let Some(active_editor) = active_editor {
|
|
|
|
self.set_active_editor(active_editor, cx);
|
|
|
|
}
|
2023-04-20 15:29:14 +00:00
|
|
|
self.switch_mode(Mode::Normal, false, cx);
|
|
|
|
}
|
|
|
|
self.sync_vim_settings(cx);
|
|
|
|
});
|
2022-03-26 20:30:55 +00:00
|
|
|
}
|
2022-03-25 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 15:29:14 +00:00
|
|
|
fn sync_vim_settings(&self, cx: &mut WindowContext) {
|
2022-04-15 23:00:44 +00:00
|
|
|
let state = &self.state;
|
|
|
|
let cursor_shape = state.cursor_shape();
|
2022-05-23 18:04:26 +00:00
|
|
|
|
2023-04-17 09:17:35 +00:00
|
|
|
self.update_active_editor(cx, |editor, cx| {
|
|
|
|
if self.enabled && editor.mode() == EditorMode::Full {
|
|
|
|
editor.set_cursor_shape(cursor_shape, cx);
|
|
|
|
editor.set_clip_at_line_ends(state.clip_at_line_end(), cx);
|
2023-06-28 17:47:14 +00:00
|
|
|
editor.set_collapse_matches(true);
|
2023-04-17 09:17:35 +00:00
|
|
|
editor.set_input_enabled(!state.vim_controlled());
|
|
|
|
editor.selections.line_mode = matches!(state.mode, Mode::Visual { line: true });
|
|
|
|
let context_layer = state.keymap_context_layer();
|
2023-05-04 10:04:30 +00:00
|
|
|
editor.set_keymap_context_layer::<Self>(context_layer, cx);
|
2023-02-08 23:01:42 +00:00
|
|
|
} else {
|
2023-06-28 17:47:14 +00:00
|
|
|
// Note: set_collapse_matches is not in unhook_vim_settings, as that method is called on blur,
|
|
|
|
// but we need collapse_matches to persist when the search bar is focused.
|
|
|
|
editor.set_collapse_matches(false);
|
2023-07-21 01:41:38 +00:00
|
|
|
self.unhook_vim_settings(editor, cx);
|
2022-03-26 20:30:55 +00:00
|
|
|
}
|
2023-04-17 09:17:35 +00:00
|
|
|
});
|
2022-03-25 02:24:36 +00:00
|
|
|
}
|
2023-02-08 23:01:42 +00:00
|
|
|
|
2023-07-21 01:41:38 +00:00
|
|
|
fn unhook_vim_settings(&self, editor: &mut Editor, cx: &mut ViewContext<Editor>) {
|
2023-04-17 09:17:35 +00:00
|
|
|
editor.set_cursor_shape(CursorShape::Bar, cx);
|
|
|
|
editor.set_clip_at_line_ends(false, cx);
|
|
|
|
editor.set_input_enabled(true);
|
|
|
|
editor.selections.line_mode = false;
|
2023-07-21 01:41:38 +00:00
|
|
|
|
|
|
|
// we set the VimEnabled context on all editors so that we
|
|
|
|
// can distinguish between vim mode and non-vim mode in the BufferSearchBar.
|
|
|
|
// This is a bit of a hack, but currently the search crate does not depend on vim,
|
|
|
|
// and it seems nice to keep it that way.
|
|
|
|
if self.enabled {
|
|
|
|
let mut context = KeymapContext::default();
|
|
|
|
context.add_identifier("VimEnabled");
|
|
|
|
editor.set_keymap_context_layer::<Self>(context, cx)
|
|
|
|
} else {
|
|
|
|
editor.remove_keymap_context_layer::<Self>(cx);
|
|
|
|
}
|
2023-02-08 23:01:42 +00:00
|
|
|
}
|
2022-03-25 02:24:36 +00:00
|
|
|
}
|
2023-04-20 21:25:11 +00:00
|
|
|
|
2023-05-10 18:06:55 +00:00
|
|
|
impl Setting for VimModeSetting {
|
|
|
|
const KEY: Option<&'static str> = Some("vim_mode");
|
|
|
|
|
|
|
|
type FileContent = Option<bool>;
|
|
|
|
|
|
|
|
fn load(
|
|
|
|
default_value: &Self::FileContent,
|
|
|
|
user_values: &[&Self::FileContent],
|
|
|
|
_: &AppContext,
|
2023-05-11 21:40:35 +00:00
|
|
|
) -> Result<Self> {
|
|
|
|
Ok(Self(user_values.iter().rev().find_map(|v| **v).unwrap_or(
|
|
|
|
default_value.ok_or_else(Self::missing_default)?,
|
|
|
|
)))
|
2023-05-10 18:06:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-20 21:25:11 +00:00
|
|
|
fn local_selections_changed(newest_empty: bool, cx: &mut WindowContext) {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
|
|
|
if vim.enabled && vim.state.mode == Mode::Normal && !newest_empty {
|
|
|
|
vim.switch_mode(Mode::Visual { line: false }, false, cx)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|