diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 256ef2284c..59143e8a39 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -575,6 +575,7 @@ pub struct Editor { searchable: bool, cursor_shape: CursorShape, collapse_matches: bool, + autoindent_mode: Option, workspace: Option<(WeakViewHandle, i64)>, keymap_context_layers: BTreeMap, input_enabled: bool, @@ -1409,6 +1410,7 @@ impl Editor { searchable: true, override_text_style: None, cursor_shape: Default::default(), + autoindent_mode: Some(AutoindentMode::EachLine), collapse_matches: false, workspace: None, keymap_context_layers: Default::default(), @@ -1587,6 +1589,14 @@ impl Editor { self.input_enabled = input_enabled; } + pub fn set_autoindent(&mut self, autoindent: bool) { + if autoindent { + self.autoindent_mode = Some(AutoindentMode::EachLine); + } else { + self.autoindent_mode = None; + } + } + pub fn set_read_only(&mut self, read_only: bool) { self.read_only = read_only; } @@ -1719,7 +1729,7 @@ impl Editor { } self.buffer.update(cx, |buffer, cx| { - buffer.edit(edits, Some(AutoindentMode::EachLine), cx) + buffer.edit(edits, self.autoindent_mode.clone(), cx) }); } @@ -2194,7 +2204,7 @@ impl Editor { drop(snapshot); self.transact(cx, |this, cx| { this.buffer.update(cx, |buffer, cx| { - buffer.edit(edits, Some(AutoindentMode::EachLine), cx); + buffer.edit(edits, this.autoindent_mode.clone(), cx); }); let new_anchor_selections = new_selections.iter().map(|e| &e.0); @@ -2504,6 +2514,7 @@ impl Editor { } pub fn insert(&mut self, text: &str, cx: &mut ViewContext) { + dbg!("insert!"); self.insert_with_autoindent_mode( text, Some(AutoindentMode::Block { @@ -3003,7 +3014,7 @@ impl Editor { this.buffer.update(cx, |buffer, cx| { buffer.edit( ranges.iter().map(|range| (range.clone(), text)), - Some(AutoindentMode::EachLine), + this.autoindent_mode.clone(), cx, ); }); diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index 8417c411f2..df807c8f28 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -364,6 +364,7 @@ impl MultiBuffer { S: ToOffset, T: Into>, { + dbg!("edit", &autoindent_mode); if self.buffers.borrow().is_empty() { return; } diff --git a/crates/vim/src/state.rs b/crates/vim/src/state.rs index 66aaec02b9..5f146aa690 100644 --- a/crates/vim/src/state.rs +++ b/crates/vim/src/state.rs @@ -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, diff --git a/crates/vim/src/test/neovim_connection.rs b/crates/vim/src/test/neovim_connection.rs index ddeb26164b..2c7a33909e 100644 --- a/crates/vim/src/test/neovim_connection.rs +++ b/crates/vim/src/test/neovim_connection.rs @@ -520,6 +520,5 @@ fn encode_ranges(text: &str, point_ranges: &Vec>) -> String { byte_range }) .collect::>(); - let ret = util::test::generate_marked_text(text, &byte_ranges[..], true); - ret + util::test::generate_marked_text(text, &byte_ranges[..], true); } diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index df35e951d2..e3f7c7dd10 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -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::(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 diff --git a/crates/vim/src/visual.rs b/crates/vim/src/visual.rs index cb4d865dc9..6dff69a6e4 100644 --- a/crates/vim/src/visual.rs +++ b/crates/vim/src/visual.rs @@ -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 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