Disable autoindent in visual block insert mode

This commit is contained in:
Conrad Irwin 2023-08-16 10:44:59 -06:00
parent 1b4dd49b1d
commit 7f06191c9f
6 changed files with 24 additions and 7 deletions

View file

@ -90,6 +90,10 @@ impl VimState {
)
}
pub fn should_autoindent(&self) -> bool {
!(self.mode == Mode::Insert && self.last_mode == Mode::VisualBlock)
}
pub fn clip_at_line_ends(&self) -> bool {
match self.mode {
Mode::Insert | Mode::Visual | Mode::VisualLine | Mode::VisualBlock => false,

View file

@ -520,6 +520,5 @@ fn encode_ranges(text: &str, point_ranges: &Vec<Range<Point>>) -> String {
byte_range
})
.collect::<Vec<_>>();
let ret = util::test::generate_marked_text(text, &byte_ranges[..], true);
ret
util::test::generate_marked_text(text, &byte_ranges[..], true);
}

View file

@ -339,6 +339,7 @@ impl Vim {
editor.set_clip_at_line_ends(state.clip_at_line_ends(), cx);
editor.set_collapse_matches(true);
editor.set_input_enabled(!state.vim_controlled());
editor.set_autoindent(state.should_autoindent());
editor.selections.line_mode = matches!(state.mode, Mode::VisualLine);
let context_layer = state.keymap_context_layer();
editor.set_keymap_context_layer::<Self>(context_layer, cx);
@ -355,6 +356,7 @@ impl Vim {
editor.set_cursor_shape(CursorShape::Bar, cx);
editor.set_clip_at_line_ends(false, cx);
editor.set_input_enabled(true);
editor.set_autoindent(true);
editor.selections.line_mode = false;
// we set the VimEnabled context on all editors so that we

View file

@ -192,7 +192,7 @@ pub fn visual_block_motion(
let start = map.clip_point(DisplayPoint::new(row, columns.start), Bias::Left);
let end = map.clip_point(DisplayPoint::new(row, columns.end), Bias::Left);
if columns.start <= map.line_len(row) {
let mut selection = Selection {
let selection = Selection {
id: s.new_selection_id(),
start: start.to_point(map),
end: end.to_point(map),
@ -392,7 +392,7 @@ pub fn paste(_: &mut Workspace, _: &VisualPaste, cx: &mut ViewContext<Workspace>
linewise = all_selections_were_entire_line;
}
let selection = selection.clone();
let mut selection = selection.clone();
if !selection.reversed {
let adjusted = selection.end;
// If the selection is empty, move both the start and end forward one