mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
vim: Fix some problems with visual mode testing (#8461)
Release Notes: - N/A
This commit is contained in:
parent
079c31fcac
commit
8cf36ae603
@ -41,14 +41,9 @@ impl Render for ModeIndicator {
|
|||||||
return div().into_any();
|
return div().into_any();
|
||||||
};
|
};
|
||||||
|
|
||||||
let text = match mode {
|
Label::new(format!("-- {} --", mode))
|
||||||
Mode::Normal => "-- NORMAL --",
|
.size(LabelSize::Small)
|
||||||
Mode::Insert => "-- INSERT --",
|
.into_any_element()
|
||||||
Mode::Visual => "-- VISUAL --",
|
|
||||||
Mode::VisualLine => "-- VISUAL LINE --",
|
|
||||||
Mode::VisualBlock => "-- VISUAL BLOCK --",
|
|
||||||
};
|
|
||||||
Label::new(text).size(LabelSize::Small).into_any_element()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,17 +131,22 @@ impl Object {
|
|||||||
|
|
||||||
pub fn target_visual_mode(self, current_mode: Mode) -> Mode {
|
pub fn target_visual_mode(self, current_mode: Mode) -> Mode {
|
||||||
match self {
|
match self {
|
||||||
Object::Word { .. } if current_mode == Mode::VisualLine => Mode::Visual,
|
Object::Word { .. }
|
||||||
Object::Word { .. } => current_mode,
|
| Object::Sentence
|
||||||
Object::Sentence
|
|
||||||
| Object::Quotes
|
| Object::Quotes
|
||||||
| Object::BackQuotes
|
| Object::BackQuotes
|
||||||
| Object::DoubleQuotes
|
| Object::DoubleQuotes => {
|
||||||
| Object::VerticalBars
|
if current_mode == Mode::VisualBlock {
|
||||||
| Object::Parentheses
|
Mode::VisualBlock
|
||||||
|
} else {
|
||||||
|
Mode::Visual
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Object::Parentheses
|
||||||
| Object::SquareBrackets
|
| Object::SquareBrackets
|
||||||
| Object::CurlyBrackets
|
| Object::CurlyBrackets
|
||||||
| Object::AngleBrackets
|
| Object::AngleBrackets
|
||||||
|
| Object::VerticalBars
|
||||||
| Object::Argument => Mode::Visual,
|
| Object::Argument => Mode::Visual,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{ops::Range, sync::Arc};
|
use std::{fmt::Display, ops::Range, sync::Arc};
|
||||||
|
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use gpui::{Action, KeyContext};
|
use gpui::{Action, KeyContext};
|
||||||
@ -17,6 +17,18 @@ pub enum Mode {
|
|||||||
VisualBlock,
|
VisualBlock,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for Mode {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Mode::Normal => write!(f, "NORMAL"),
|
||||||
|
Mode::Insert => write!(f, "INSERT"),
|
||||||
|
Mode::Visual => write!(f, "VISUAL"),
|
||||||
|
Mode::VisualLine => write!(f, "VISUAL LINE"),
|
||||||
|
Mode::VisualBlock => write!(f, "VISUAL BLOCK"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Mode {
|
impl Mode {
|
||||||
pub fn is_visual(&self) -> bool {
|
pub fn is_visual(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
|
@ -190,8 +190,10 @@ impl NeovimBackedTestContext {
|
|||||||
self.is_dirty = false;
|
self.is_dirty = false;
|
||||||
let marked_text = marked_text.replace("•", " ");
|
let marked_text = marked_text.replace("•", " ");
|
||||||
let neovim = self.neovim_state().await;
|
let neovim = self.neovim_state().await;
|
||||||
|
let neovim_mode = self.neovim_mode().await;
|
||||||
let editor = self.editor_state();
|
let editor = self.editor_state();
|
||||||
if neovim == marked_text && neovim == editor {
|
let editor_mode = self.mode();
|
||||||
|
if neovim == marked_text && neovim == editor && neovim_mode == editor_mode {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let initial_state = self
|
let initial_state = self
|
||||||
@ -213,16 +215,18 @@ impl NeovimBackedTestContext {
|
|||||||
{}
|
{}
|
||||||
# currently expected:
|
# currently expected:
|
||||||
{}
|
{}
|
||||||
# neovim state:
|
# neovim ({}):
|
||||||
{}
|
{}
|
||||||
# zed state:
|
# zed ({}):
|
||||||
{}"},
|
{}"},
|
||||||
message,
|
message,
|
||||||
initial_state,
|
initial_state,
|
||||||
self.recent_keystrokes.join(" "),
|
self.recent_keystrokes.join(" "),
|
||||||
marked_text.replace(" \n", "•\n"),
|
marked_text.replace(" \n", "•\n"),
|
||||||
|
neovim_mode,
|
||||||
neovim.replace(" \n", "•\n"),
|
neovim.replace(" \n", "•\n"),
|
||||||
editor.replace(" \n", "•\n")
|
editor_mode,
|
||||||
|
editor.replace(" \n", "•\n"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,27 +300,31 @@ impl NeovimBackedTestContext {
|
|||||||
pub async fn assert_state_matches(&mut self) {
|
pub async fn assert_state_matches(&mut self) {
|
||||||
self.is_dirty = false;
|
self.is_dirty = false;
|
||||||
let neovim = self.neovim_state().await;
|
let neovim = self.neovim_state().await;
|
||||||
|
let neovim_mode = self.neovim_mode().await;
|
||||||
let editor = self.editor_state();
|
let editor = self.editor_state();
|
||||||
|
let editor_mode = self.mode();
|
||||||
let initial_state = self
|
let initial_state = self
|
||||||
.last_set_state
|
.last_set_state
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap_or(&"N/A".to_string())
|
.unwrap_or(&"N/A".to_string())
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
if neovim != editor {
|
if neovim != editor || neovim_mode != editor_mode {
|
||||||
panic!(
|
panic!(
|
||||||
indoc! {"Test failed (zed does not match nvim behaviour)
|
indoc! {"Test failed (zed does not match nvim behaviour)
|
||||||
# initial state:
|
# initial state:
|
||||||
{}
|
{}
|
||||||
# keystrokes:
|
# keystrokes:
|
||||||
{}
|
{}
|
||||||
# neovim state:
|
# neovim ({}):
|
||||||
{}
|
{}
|
||||||
# zed state:
|
# zed ({}):
|
||||||
{}"},
|
{}"},
|
||||||
initial_state,
|
initial_state,
|
||||||
self.recent_keystrokes.join(" "),
|
self.recent_keystrokes.join(" "),
|
||||||
|
neovim_mode,
|
||||||
neovim,
|
neovim,
|
||||||
|
editor_mode,
|
||||||
editor,
|
editor,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -419,7 +419,7 @@ impl NeovimConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Mode::Visual) | Some(Mode::VisualLine) | Some(Mode::VisualBlock) => {
|
Some(Mode::Visual) | Some(Mode::VisualLine) | Some(Mode::VisualBlock) => {
|
||||||
if selection_col > cursor_col {
|
if (selection_row, selection_col) > (cursor_row, cursor_col) {
|
||||||
let selection_line_length =
|
let selection_line_length =
|
||||||
self.read_position("echo strlen(getline(line('v')))").await;
|
self.read_position("echo strlen(getline(line('v')))").await;
|
||||||
if selection_line_length > selection_col {
|
if selection_line_length > selection_col {
|
||||||
|
@ -1005,7 +1005,6 @@ mod test {
|
|||||||
cx.simulate_shared_keystrokes(["ctrl-v", "l"]).await;
|
cx.simulate_shared_keystrokes(["ctrl-v", "l"]).await;
|
||||||
cx.simulate_shared_keystrokes(["a", "]"]).await;
|
cx.simulate_shared_keystrokes(["a", "]"]).await;
|
||||||
cx.assert_shared_state("hello (in «[parens]ˇ» o)").await;
|
cx.assert_shared_state("hello (in «[parens]ˇ» o)").await;
|
||||||
assert_eq!(cx.mode(), Mode::Visual);
|
|
||||||
cx.simulate_shared_keystrokes(["i", "("]).await;
|
cx.simulate_shared_keystrokes(["i", "("]).await;
|
||||||
cx.assert_shared_state("hello («in [parens] oˇ»)").await;
|
cx.assert_shared_state("hello («in [parens] oˇ»)").await;
|
||||||
|
|
||||||
@ -1016,7 +1015,6 @@ mod test {
|
|||||||
assert_eq!(cx.mode(), Mode::VisualBlock);
|
assert_eq!(cx.mode(), Mode::VisualBlock);
|
||||||
cx.simulate_shared_keystrokes(["o", "a", "s"]).await;
|
cx.simulate_shared_keystrokes(["o", "a", "s"]).await;
|
||||||
cx.assert_shared_state("«ˇhello in a word» again.").await;
|
cx.assert_shared_state("«ˇhello in a word» again.").await;
|
||||||
assert_eq!(cx.mode(), Mode::Visual);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
Loading…
Reference in New Issue
Block a user