mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-10 20:41:59 +00:00
vim: Convert from visual mode to normal mode with a single click (#6985)
Release Notes: - Fixed #4319 Here is a demo after the fix: https://github.com/zed-industries/zed/assets/22256154/a690f146-73c9-4b0e-8527-e4faf690cca2 Actually I'm not really sure should I submit my idea to discussion, since it's not a large change, and it's something like a bug fix. So I directly create a pr here. --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
parent
15edc46827
commit
430f5d5d53
1 changed files with 19 additions and 7 deletions
|
@ -204,7 +204,8 @@ impl Vim {
|
||||||
let editor = editor.read(cx);
|
let editor = editor.read(cx);
|
||||||
if editor.leader_peer_id().is_none() {
|
if editor.leader_peer_id().is_none() {
|
||||||
let newest = editor.selections.newest::<usize>(cx);
|
let newest = editor.selections.newest::<usize>(cx);
|
||||||
local_selections_changed(newest, cx);
|
let is_multicursor = editor.selections.count() > 1;
|
||||||
|
local_selections_changed(newest, is_multicursor, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EditorEvent::InputIgnored { text } => {
|
EditorEvent::InputIgnored { text } => {
|
||||||
|
@ -626,13 +627,24 @@ impl Settings for VimModeSetting {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_selections_changed(newest: Selection<usize>, cx: &mut WindowContext) {
|
fn local_selections_changed(
|
||||||
|
newest: Selection<usize>,
|
||||||
|
is_multicursor: bool,
|
||||||
|
cx: &mut WindowContext,
|
||||||
|
) {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
if vim.enabled && vim.state().mode == Mode::Normal && !newest.is_empty() {
|
if vim.enabled {
|
||||||
if matches!(newest.goal, SelectionGoal::HorizontalRange { .. }) {
|
if vim.state().mode == Mode::Normal && !newest.is_empty() {
|
||||||
vim.switch_mode(Mode::VisualBlock, false, cx);
|
if matches!(newest.goal, SelectionGoal::HorizontalRange { .. }) {
|
||||||
} else {
|
vim.switch_mode(Mode::VisualBlock, false, cx);
|
||||||
vim.switch_mode(Mode::Visual, false, cx)
|
} else {
|
||||||
|
vim.switch_mode(Mode::Visual, false, cx)
|
||||||
|
}
|
||||||
|
} else if newest.is_empty()
|
||||||
|
&& !is_multicursor
|
||||||
|
&& [Mode::Visual, Mode::VisualLine, Mode::VisualBlock].contains(&vim.state().mode)
|
||||||
|
{
|
||||||
|
vim.switch_mode(Mode::Normal, true, cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue