Initialize the active editor when vim mode is enabled
Instead of waiting for a focus event. This makes more tests pass.
This commit is contained in:
parent
0d5eea8169
commit
137d9384b5
11 changed files with 127 additions and 116 deletions
|
@ -735,7 +735,7 @@ mod tests {
|
||||||
.map_or(5, |o| o.parse().expect("invalid OPERATIONS variable"));
|
.map_or(5, |o| o.parse().expect("invalid OPERATIONS variable"));
|
||||||
|
|
||||||
for seed in starting_seed..(starting_seed + num_iterations) {
|
for seed in starting_seed..(starting_seed + num_iterations) {
|
||||||
dbg!(seed);
|
eprintln!("seed = {}", seed);
|
||||||
let mut rng = StdRng::seed_from_u64(seed);
|
let mut rng = StdRng::seed_from_u64(seed);
|
||||||
|
|
||||||
let rng = &mut rng;
|
let rng = &mut rng;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use editor::{EditorBlurred, EditorFocused, EditorMode, EditorReleased, Event};
|
use editor::{EditorBlurred, EditorFocused, EditorMode, EditorReleased, Event};
|
||||||
use gpui::AppContext;
|
use gpui::{AppContext, WindowContext};
|
||||||
|
|
||||||
use crate::{state::Mode, Vim};
|
use crate::{state::Mode, Vim};
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ pub fn init(cx: &mut AppContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
|
fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
|
||||||
|
cx.update_window(editor.window_id(), |cx| {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
vim.update_active_editor(cx, |previously_active_editor, cx| {
|
vim.update_active_editor(cx, |previously_active_editor, cx| {
|
||||||
Vim::unhook_vim_settings(previously_active_editor, cx);
|
Vim::unhook_vim_settings(previously_active_editor, cx);
|
||||||
|
@ -42,9 +43,11 @@ fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
|
||||||
|
|
||||||
vim.sync_vim_settings(cx);
|
vim.sync_vim_settings(cx);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
|
fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
|
||||||
|
cx.update_window(editor.window_id(), |cx| {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
if let Some(previous_editor) = vim.active_editor.clone() {
|
if let Some(previous_editor) = vim.active_editor.clone() {
|
||||||
if previous_editor == editor.clone() {
|
if previous_editor == editor.clone() {
|
||||||
|
@ -55,10 +58,12 @@ fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
|
||||||
cx.update_window(editor.window_id(), |cx| {
|
cx.update_window(editor.window_id(), |cx| {
|
||||||
editor.update(cx, |editor, cx| Vim::unhook_vim_settings(editor, cx))
|
editor.update(cx, |editor, cx| Vim::unhook_vim_settings(editor, cx))
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) {
|
fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) {
|
||||||
|
cx.update_window(editor.window_id(), |cx| {
|
||||||
cx.update_default_global(|vim: &mut Vim, _| {
|
cx.update_default_global(|vim: &mut Vim, _| {
|
||||||
if let Some(previous_editor) = vim.active_editor.clone() {
|
if let Some(previous_editor) = vim.active_editor.clone() {
|
||||||
if previous_editor == editor.clone() {
|
if previous_editor == editor.clone() {
|
||||||
|
@ -66,9 +71,10 @@ fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_selections_changed(newest_empty: bool, cx: &mut AppContext) {
|
fn local_selections_changed(newest_empty: bool, cx: &mut WindowContext) {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
if vim.enabled && vim.state.mode == Mode::Normal && !newest_empty {
|
if vim.enabled && vim.state.mode == Mode::Normal && !newest_empty {
|
||||||
vim.switch_mode(Mode::Visual { line: false }, false, cx)
|
vim.switch_mode(Mode::Visual { line: false }, false, cx)
|
||||||
|
|
|
@ -5,7 +5,7 @@ use editor::{
|
||||||
display_map::{DisplaySnapshot, ToDisplayPoint},
|
display_map::{DisplaySnapshot, ToDisplayPoint},
|
||||||
movement, Bias, CharKind, DisplayPoint, ToOffset,
|
movement, Bias, CharKind, DisplayPoint, ToOffset,
|
||||||
};
|
};
|
||||||
use gpui::{actions, impl_actions, AppContext};
|
use gpui::{actions, impl_actions, AppContext, WindowContext};
|
||||||
use language::{Point, Selection, SelectionGoal};
|
use language::{Point, Selection, SelectionGoal};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
@ -116,7 +116,7 @@ pub fn init(cx: &mut AppContext) {
|
||||||
cx.add_action(|_: &mut Workspace, &NextLineStart, cx: _| motion(Motion::NextLineStart, cx))
|
cx.add_action(|_: &mut Workspace, &NextLineStart, cx: _| motion(Motion::NextLineStart, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn motion(motion: Motion, cx: &mut AppContext) {
|
pub(crate) fn motion(motion: Motion, cx: &mut WindowContext) {
|
||||||
if let Some(Operator::Namespace(_))
|
if let Some(Operator::Namespace(_))
|
||||||
| Some(Operator::FindForward { .. })
|
| Some(Operator::FindForward { .. })
|
||||||
| Some(Operator::FindBackward { .. }) = Vim::read(cx).active_operator()
|
| Some(Operator::FindBackward { .. }) = Vim::read(cx).active_operator()
|
||||||
|
|
|
@ -16,7 +16,7 @@ use editor::{
|
||||||
scroll::{autoscroll::Autoscroll, scroll_amount::ScrollAmount},
|
scroll::{autoscroll::Autoscroll, scroll_amount::ScrollAmount},
|
||||||
Anchor, Bias, ClipboardSelection, DisplayPoint, Editor,
|
Anchor, Bias, ClipboardSelection, DisplayPoint, Editor,
|
||||||
};
|
};
|
||||||
use gpui::{actions, impl_actions, AppContext, ViewContext};
|
use gpui::{actions, impl_actions, AppContext, ViewContext, WindowContext};
|
||||||
use language::{AutoindentMode, Point, SelectionGoal};
|
use language::{AutoindentMode, Point, SelectionGoal};
|
||||||
use log::error;
|
use log::error;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -94,7 +94,7 @@ pub fn normal_motion(
|
||||||
motion: Motion,
|
motion: Motion,
|
||||||
operator: Option<Operator>,
|
operator: Option<Operator>,
|
||||||
times: usize,
|
times: usize,
|
||||||
cx: &mut AppContext,
|
cx: &mut WindowContext,
|
||||||
) {
|
) {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
match operator {
|
match operator {
|
||||||
|
@ -110,7 +110,7 @@ pub fn normal_motion(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn normal_object(object: Object, cx: &mut AppContext) {
|
pub fn normal_object(object: Object, cx: &mut WindowContext) {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
match vim.state.operator_stack.pop() {
|
match vim.state.operator_stack.pop() {
|
||||||
Some(Operator::Object { around }) => match vim.state.operator_stack.pop() {
|
Some(Operator::Object { around }) => match vim.state.operator_stack.pop() {
|
||||||
|
@ -129,7 +129,7 @@ pub fn normal_object(object: Object, cx: &mut AppContext) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_cursor(vim: &mut Vim, motion: Motion, times: usize, cx: &mut AppContext) {
|
fn move_cursor(vim: &mut Vim, motion: Motion, times: usize, cx: &mut WindowContext) {
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||||
s.move_cursors_with(|map, cursor, goal| {
|
s.move_cursors_with(|map, cursor, goal| {
|
||||||
|
@ -424,7 +424,7 @@ fn scroll(editor: &mut Editor, amount: &ScrollAmount, cx: &mut ViewContext<Edito
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn normal_replace(text: Arc<str>, cx: &mut AppContext) {
|
pub(crate) fn normal_replace(text: Arc<str>, cx: &mut WindowContext) {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.transact(cx, |editor, cx| {
|
editor.transact(cx, |editor, cx| {
|
||||||
|
|
|
@ -3,10 +3,10 @@ use editor::{
|
||||||
char_kind, display_map::DisplaySnapshot, movement, scroll::autoscroll::Autoscroll, CharKind,
|
char_kind, display_map::DisplaySnapshot, movement, scroll::autoscroll::Autoscroll, CharKind,
|
||||||
DisplayPoint,
|
DisplayPoint,
|
||||||
};
|
};
|
||||||
use gpui::AppContext;
|
use gpui::WindowContext;
|
||||||
use language::Selection;
|
use language::Selection;
|
||||||
|
|
||||||
pub fn change_motion(vim: &mut Vim, motion: Motion, times: usize, cx: &mut AppContext) {
|
pub fn change_motion(vim: &mut Vim, motion: Motion, times: usize, cx: &mut WindowContext) {
|
||||||
// Some motions ignore failure when switching to normal mode
|
// Some motions ignore failure when switching to normal mode
|
||||||
let mut motion_succeeded = matches!(
|
let mut motion_succeeded = matches!(
|
||||||
motion,
|
motion,
|
||||||
|
@ -38,7 +38,7 @@ pub fn change_motion(vim: &mut Vim, motion: Motion, times: usize, cx: &mut AppCo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn change_object(vim: &mut Vim, object: Object, around: bool, cx: &mut AppContext) {
|
pub fn change_object(vim: &mut Vim, object: Object, around: bool, cx: &mut WindowContext) {
|
||||||
let mut objects_found = false;
|
let mut objects_found = false;
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
|
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::{motion::Motion, object::Object, utils::copy_selections_content, Vim};
|
use crate::{motion::Motion, object::Object, utils::copy_selections_content, Vim};
|
||||||
use collections::{HashMap, HashSet};
|
use collections::{HashMap, HashSet};
|
||||||
use editor::{display_map::ToDisplayPoint, scroll::autoscroll::Autoscroll, Bias};
|
use editor::{display_map::ToDisplayPoint, scroll::autoscroll::Autoscroll, Bias};
|
||||||
use gpui::AppContext;
|
use gpui::WindowContext;
|
||||||
|
|
||||||
pub fn delete_motion(vim: &mut Vim, motion: Motion, times: usize, cx: &mut AppContext) {
|
pub fn delete_motion(vim: &mut Vim, motion: Motion, times: usize, cx: &mut WindowContext) {
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.transact(cx, |editor, cx| {
|
editor.transact(cx, |editor, cx| {
|
||||||
editor.set_clip_at_line_ends(false, cx);
|
editor.set_clip_at_line_ends(false, cx);
|
||||||
|
@ -36,7 +36,7 @@ pub fn delete_motion(vim: &mut Vim, motion: Motion, times: usize, cx: &mut AppCo
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_object(vim: &mut Vim, object: Object, around: bool, cx: &mut AppContext) {
|
pub fn delete_object(vim: &mut Vim, object: Object, around: bool, cx: &mut WindowContext) {
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.transact(cx, |editor, cx| {
|
editor.transact(cx, |editor, cx| {
|
||||||
editor.set_clip_at_line_ends(false, cx);
|
editor.set_clip_at_line_ends(false, cx);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::{motion::Motion, object::Object, utils::copy_selections_content, Vim};
|
use crate::{motion::Motion, object::Object, utils::copy_selections_content, Vim};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use gpui::AppContext;
|
use gpui::WindowContext;
|
||||||
|
|
||||||
pub fn yank_motion(vim: &mut Vim, motion: Motion, times: usize, cx: &mut AppContext) {
|
pub fn yank_motion(vim: &mut Vim, motion: Motion, times: usize, cx: &mut WindowContext) {
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.transact(cx, |editor, cx| {
|
editor.transact(cx, |editor, cx| {
|
||||||
editor.set_clip_at_line_ends(false, cx);
|
editor.set_clip_at_line_ends(false, cx);
|
||||||
|
@ -25,7 +25,7 @@ pub fn yank_motion(vim: &mut Vim, motion: Motion, times: usize, cx: &mut AppCont
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn yank_object(vim: &mut Vim, object: Object, around: bool, cx: &mut AppContext) {
|
pub fn yank_object(vim: &mut Vim, object: Object, around: bool, cx: &mut WindowContext) {
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.transact(cx, |editor, cx| {
|
editor.transact(cx, |editor, cx| {
|
||||||
editor.set_clip_at_line_ends(false, cx);
|
editor.set_clip_at_line_ends(false, cx);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
use editor::{char_kind, display_map::DisplaySnapshot, movement, Bias, CharKind, DisplayPoint};
|
use editor::{char_kind, display_map::DisplaySnapshot, movement, Bias, CharKind, DisplayPoint};
|
||||||
use gpui::{actions, impl_actions, AppContext};
|
use gpui::{actions, impl_actions, AppContext, WindowContext};
|
||||||
use language::Selection;
|
use language::Selection;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
@ -61,7 +61,7 @@ pub fn init(cx: &mut AppContext) {
|
||||||
cx.add_action(|_: &mut Workspace, _: &AngleBrackets, cx: _| object(Object::AngleBrackets, cx));
|
cx.add_action(|_: &mut Workspace, _: &AngleBrackets, cx: _| object(Object::AngleBrackets, cx));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn object(object: Object, cx: &mut AppContext) {
|
fn object(object: Object, cx: &mut WindowContext) {
|
||||||
match Vim::read(cx).state.mode {
|
match Vim::read(cx).state.mode {
|
||||||
Mode::Normal => normal_object(object, cx),
|
Mode::Normal => normal_object(object, cx),
|
||||||
Mode::Visual { .. } => visual_object(object, cx),
|
Mode::Visual { .. } => visual_object(object, cx),
|
||||||
|
|
|
@ -16,19 +16,15 @@ pub struct VimTestContext<'a> {
|
||||||
|
|
||||||
impl<'a> VimTestContext<'a> {
|
impl<'a> VimTestContext<'a> {
|
||||||
pub async fn new(cx: &'a mut gpui::TestAppContext, enabled: bool) -> VimTestContext<'a> {
|
pub async fn new(cx: &'a mut gpui::TestAppContext, enabled: bool) -> VimTestContext<'a> {
|
||||||
cx.update(|cx| {
|
|
||||||
search::init(cx);
|
|
||||||
crate::init(cx);
|
|
||||||
|
|
||||||
settings::KeymapFileContent::load("keymaps/vim.json", cx).unwrap();
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut cx = EditorLspTestContext::new_rust(Default::default(), cx).await;
|
let mut cx = EditorLspTestContext::new_rust(Default::default(), cx).await;
|
||||||
|
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
cx.update_global(|settings: &mut Settings, _| {
|
cx.update_global(|settings: &mut Settings, _| {
|
||||||
settings.vim_mode = enabled;
|
settings.vim_mode = enabled;
|
||||||
});
|
});
|
||||||
|
search::init(cx);
|
||||||
|
crate::init(cx);
|
||||||
|
|
||||||
|
settings::KeymapFileContent::load("keymaps/vim.json", cx).unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Setup search toolbars and keypress hook
|
// Setup search toolbars and keypress hook
|
||||||
|
@ -80,7 +76,8 @@ impl<'a> VimTestContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_state(&mut self, text: &str, mode: Mode) -> ContextHandle {
|
pub fn set_state(&mut self, text: &str, mode: Mode) -> ContextHandle {
|
||||||
self.cx.update(|cx| {
|
let window_id = self.window_id;
|
||||||
|
self.update_window(window_id, |cx| {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
vim.switch_mode(mode, false, cx);
|
vim.switch_mode(mode, false, cx);
|
||||||
})
|
})
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub fn init(cx: &mut AppContext) {
|
||||||
// Otherwise forward cancel on to the editor
|
// Otherwise forward cancel on to the editor
|
||||||
let vim = Vim::read(cx);
|
let vim = Vim::read(cx);
|
||||||
if vim.state.mode != Mode::Normal || vim.active_operator().is_some() {
|
if vim.state.mode != Mode::Normal || vim.active_operator().is_some() {
|
||||||
AppContext::defer(cx, |cx| {
|
WindowContext::defer(cx, |cx| {
|
||||||
Vim::update(cx, |state, cx| {
|
Vim::update(cx, |state, cx| {
|
||||||
state.switch_mode(Mode::Normal, false, cx);
|
state.switch_mode(Mode::Normal, false, cx);
|
||||||
});
|
});
|
||||||
|
@ -83,14 +83,14 @@ pub fn init(cx: &mut AppContext) {
|
||||||
Vim::active_editor_input_ignored("\n".into(), cx)
|
Vim::active_editor_input_ignored("\n".into(), cx)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sync initial settings with the rest of the app
|
// Any time settings change, update vim mode to match.
|
||||||
Vim::update(cx, |vim, cx| vim.sync_vim_settings(cx));
|
cx.update_default_global(|vim: &mut Vim, cx: &mut AppContext| {
|
||||||
|
vim.set_enabled(cx.global::<Settings>().vim_mode, cx)
|
||||||
// Any time settings change, update vim mode to match
|
});
|
||||||
cx.observe_global::<Settings, _>(|cx| {
|
cx.observe_global::<Settings, _>(|cx| {
|
||||||
Vim::update(cx, |state, cx| {
|
cx.update_default_global(|vim: &mut Vim, cx: &mut AppContext| {
|
||||||
state.set_enabled(cx.global::<Settings>().vim_mode, cx)
|
vim.set_enabled(cx.global::<Settings>().vim_mode, cx)
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
@ -135,23 +135,23 @@ impl Vim {
|
||||||
cx.default_global()
|
cx.default_global()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update<F, S>(cx: &mut AppContext, update: F) -> S
|
fn update<F, S>(cx: &mut WindowContext, update: F) -> S
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self, &mut AppContext) -> S,
|
F: FnOnce(&mut Self, &mut WindowContext) -> S,
|
||||||
{
|
{
|
||||||
cx.update_default_global(update)
|
cx.update_default_global(update)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_active_editor<S>(
|
fn update_active_editor<S>(
|
||||||
&self,
|
&self,
|
||||||
cx: &mut AppContext,
|
cx: &mut WindowContext,
|
||||||
update: impl FnOnce(&mut Editor, &mut ViewContext<Editor>) -> S,
|
update: impl FnOnce(&mut Editor, &mut ViewContext<Editor>) -> S,
|
||||||
) -> Option<S> {
|
) -> Option<S> {
|
||||||
let editor = self.active_editor.clone()?.upgrade(cx)?;
|
let editor = self.active_editor.clone()?.upgrade(cx)?;
|
||||||
cx.update_window(editor.window_id(), |cx| editor.update(cx, update))
|
Some(editor.update(cx, update))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn switch_mode(&mut self, mode: Mode, leave_selections: bool, cx: &mut AppContext) {
|
fn switch_mode(&mut self, mode: Mode, leave_selections: bool, cx: &mut WindowContext) {
|
||||||
self.state.mode = mode;
|
self.state.mode = mode;
|
||||||
self.state.operator_stack.clear();
|
self.state.operator_stack.clear();
|
||||||
|
|
||||||
|
@ -178,12 +178,12 @@ impl Vim {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_operator(&mut self, operator: Operator, cx: &mut AppContext) {
|
fn push_operator(&mut self, operator: Operator, cx: &mut WindowContext) {
|
||||||
self.state.operator_stack.push(operator);
|
self.state.operator_stack.push(operator);
|
||||||
self.sync_vim_settings(cx);
|
self.sync_vim_settings(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_number(&mut self, Number(number): &Number, cx: &mut AppContext) {
|
fn push_number(&mut self, Number(number): &Number, cx: &mut WindowContext) {
|
||||||
if let Some(Operator::Number(current_number)) = self.active_operator() {
|
if let Some(Operator::Number(current_number)) = self.active_operator() {
|
||||||
self.pop_operator(cx);
|
self.pop_operator(cx);
|
||||||
self.push_operator(Operator::Number(current_number * 10 + *number as usize), cx);
|
self.push_operator(Operator::Number(current_number * 10 + *number as usize), cx);
|
||||||
|
@ -192,14 +192,14 @@ impl Vim {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pop_operator(&mut self, cx: &mut AppContext) -> Operator {
|
fn pop_operator(&mut self, cx: &mut WindowContext) -> Operator {
|
||||||
let popped_operator = self.state.operator_stack.pop()
|
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");
|
.expect("Operator popped when no operator was on the stack. This likely means there is an invalid keymap config");
|
||||||
self.sync_vim_settings(cx);
|
self.sync_vim_settings(cx);
|
||||||
popped_operator
|
popped_operator
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pop_number_operator(&mut self, cx: &mut AppContext) -> usize {
|
fn pop_number_operator(&mut self, cx: &mut WindowContext) -> usize {
|
||||||
let mut times = 1;
|
let mut times = 1;
|
||||||
if let Some(Operator::Number(number)) = self.active_operator() {
|
if let Some(Operator::Number(number)) = self.active_operator() {
|
||||||
times = number;
|
times = number;
|
||||||
|
@ -208,7 +208,7 @@ impl Vim {
|
||||||
times
|
times
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_operator(&mut self, cx: &mut AppContext) {
|
fn clear_operator(&mut self, cx: &mut WindowContext) {
|
||||||
self.state.operator_stack.clear();
|
self.state.operator_stack.clear();
|
||||||
self.sync_vim_settings(cx);
|
self.sync_vim_settings(cx);
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ impl Vim {
|
||||||
self.state.operator_stack.last().copied()
|
self.state.operator_stack.last().copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn active_editor_input_ignored(text: Arc<str>, cx: &mut AppContext) {
|
fn active_editor_input_ignored(text: Arc<str>, cx: &mut WindowContext) {
|
||||||
if text.is_empty() {
|
if text.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -242,16 +242,6 @@ impl Vim {
|
||||||
if self.enabled != enabled {
|
if self.enabled != enabled {
|
||||||
self.enabled = enabled;
|
self.enabled = enabled;
|
||||||
self.state = Default::default();
|
self.state = Default::default();
|
||||||
if enabled {
|
|
||||||
self.switch_mode(Mode::Normal, false, cx);
|
|
||||||
}
|
|
||||||
self.sync_vim_settings(cx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sync_vim_settings(&self, cx: &mut AppContext) {
|
|
||||||
let state = &self.state;
|
|
||||||
let cursor_shape = state.cursor_shape();
|
|
||||||
|
|
||||||
cx.update_default_global::<CommandPaletteFilter, _, _>(|filter, _| {
|
cx.update_default_global::<CommandPaletteFilter, _, _>(|filter, _| {
|
||||||
if self.enabled {
|
if self.enabled {
|
||||||
|
@ -261,6 +251,24 @@ impl Vim {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cx.update_active_window(|cx| {
|
||||||
|
if self.enabled {
|
||||||
|
self.active_editor = cx
|
||||||
|
.root_view()
|
||||||
|
.downcast_ref::<Workspace>()
|
||||||
|
.and_then(|workspace| workspace.read(cx).active_item(cx))
|
||||||
|
.and_then(|item| item.downcast::<Editor>().map(|h| h.downgrade()));
|
||||||
|
self.switch_mode(Mode::Normal, false, cx);
|
||||||
|
}
|
||||||
|
self.sync_vim_settings(cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sync_vim_settings(&self, cx: &mut WindowContext) {
|
||||||
|
let state = &self.state;
|
||||||
|
let cursor_shape = state.cursor_shape();
|
||||||
|
|
||||||
self.update_active_editor(cx, |editor, cx| {
|
self.update_active_editor(cx, |editor, cx| {
|
||||||
if self.enabled && editor.mode() == EditorMode::Full {
|
if self.enabled && editor.mode() == EditorMode::Full {
|
||||||
editor.set_cursor_shape(cursor_shape, cx);
|
editor.set_cursor_shape(cursor_shape, cx);
|
||||||
|
|
|
@ -4,7 +4,7 @@ use collections::HashMap;
|
||||||
use editor::{
|
use editor::{
|
||||||
display_map::ToDisplayPoint, movement, scroll::autoscroll::Autoscroll, Bias, ClipboardSelection,
|
display_map::ToDisplayPoint, movement, scroll::autoscroll::Autoscroll, Bias, ClipboardSelection,
|
||||||
};
|
};
|
||||||
use gpui::{actions, AppContext, ViewContext};
|
use gpui::{actions, AppContext, ViewContext, WindowContext};
|
||||||
use language::{AutoindentMode, SelectionGoal};
|
use language::{AutoindentMode, SelectionGoal};
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ pub fn init(cx: &mut AppContext) {
|
||||||
cx.add_action(paste);
|
cx.add_action(paste);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visual_motion(motion: Motion, times: usize, cx: &mut AppContext) {
|
pub fn visual_motion(motion: Motion, times: usize, cx: &mut WindowContext) {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||||
|
@ -56,7 +56,7 @@ pub fn visual_motion(motion: Motion, times: usize, cx: &mut AppContext) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visual_object(object: Object, cx: &mut AppContext) {
|
pub fn visual_object(object: Object, cx: &mut WindowContext) {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
if let Operator::Object { around } = vim.pop_operator(cx) {
|
if let Operator::Object { around } = vim.pop_operator(cx) {
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
|
@ -313,7 +313,7 @@ pub fn paste(_: &mut Workspace, _: &VisualPaste, cx: &mut ViewContext<Workspace>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn visual_replace(text: Arc<str>, line: bool, cx: &mut AppContext) {
|
pub(crate) fn visual_replace(text: Arc<str>, line: bool, cx: &mut WindowContext) {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.transact(cx, |editor, cx| {
|
editor.transact(cx, |editor, cx| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue