WIP line mode operations

This commit is contained in:
Keith Simmons 2022-05-18 11:10:24 -07:00
parent 8044586296
commit d7d17b2148
15 changed files with 166 additions and 30 deletions

View file

@ -18,22 +18,29 @@ fn editor_created(EditorCreated(editor): &EditorCreated, cx: &mut MutableAppCont
}
fn editor_focused(EditorFocused(editor): &EditorFocused, cx: &mut MutableAppContext) {
Vim::update(cx, |state, cx| {
state.active_editor = Some(editor.downgrade());
Vim::update(cx, |vim, cx| {
vim.active_editor = Some(editor.downgrade());
vim.selection_subscription = Some(cx.subscribe(editor, |editor, event, cx| {
if let editor::Event::SelectionsChanged { local: true } = event {
let newest_empty = !editor.read(cx).selections.newest::<usize>(cx).is_empty();
editor_local_selections_changed(newest_empty, cx);
}
}));
if editor.read(cx).mode() != EditorMode::Full {
state.switch_mode(Mode::Insert, cx);
vim.switch_mode(Mode::Insert, cx);
}
});
}
fn editor_blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut MutableAppContext) {
Vim::update(cx, |state, cx| {
if let Some(previous_editor) = state.active_editor.clone() {
Vim::update(cx, |vim, cx| {
if let Some(previous_editor) = vim.active_editor.clone() {
if previous_editor == editor.clone() {
state.active_editor = None;
vim.active_editor = None;
}
}
state.sync_editor_options(cx);
vim.sync_editor_options(cx);
})
}
@ -47,3 +54,11 @@ fn editor_released(EditorReleased(editor): &EditorReleased, cx: &mut MutableAppC
}
});
}
fn editor_local_selections_changed(newest_empty: bool, cx: &mut MutableAppContext) {
Vim::update(cx, |vim, cx| {
if vim.state.mode == Mode::Normal && !newest_empty {
vim.switch_mode(Mode::Visual, cx)
}
})
}