vim: Surround in visual mode (#13347)
Adds support for surrounding text in visual/visual-line/visual-block mode by re-using the `AddSurrounds` operator. There is no default binding though so the user must follow the instructions to enable it. Note that the behaviour varies slightly for the visual-line and visual-block modes. In visual-line mode the surrounds are placed on separate lines (the vim-surround extension also indents the contents but I opted not to as that behaviour is less important with the use of code formatters). In visual-block mode each of the selected regions is surrounded and the cursor returns to the beginning of the selection after the action is complete. Release Notes: - Added action to surround text in visual mode (no default binding). Fixes #13122
This commit is contained in:
parent
5a8c2a4a88
commit
77b2da2b42
4 changed files with 167 additions and 9 deletions
|
@ -39,7 +39,7 @@ use serde_derive::Serialize;
|
|||
use settings::{update_settings_file, Settings, SettingsSources, SettingsStore};
|
||||
use state::{EditorState, Mode, Operator, RecordedSelection, Register, WorkspaceState};
|
||||
use std::{ops::Range, sync::Arc};
|
||||
use surrounds::{add_surrounds, change_surrounds, delete_surrounds};
|
||||
use surrounds::{add_surrounds, change_surrounds, delete_surrounds, SurroundsType};
|
||||
use ui::BorrowAppContext;
|
||||
use visual::{visual_block_motion, visual_replace};
|
||||
use workspace::{self, Workspace};
|
||||
|
@ -861,6 +861,10 @@ impl Vim {
|
|||
Vim::update(cx, |vim, cx| vim.clear_operator(cx));
|
||||
}
|
||||
}
|
||||
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => {
|
||||
add_surrounds(text, SurroundsType::Selection, cx);
|
||||
Vim::update(cx, |vim, cx| vim.clear_operator(cx));
|
||||
}
|
||||
_ => Vim::update(cx, |vim, cx| vim.clear_operator(cx)),
|
||||
},
|
||||
Some(Operator::ChangeSurrounds { target }) => match Vim::read(cx).state().mode {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue