vim: Refactor and fix multiline operations (#25055)

Changes:
- [x] Cursor at the start during yank operations on objects (`yip`,
`yab` etc).
- [x] Refactors this: Trim all leading and trailing whitespace from
inner multiline bracket selection.
  - This leaves a nicely indented line when doing `ci{` `vi{d` etc
  - [x] Checks for empty selection
  - [x] Removed moving cursor to the start in visual bracket operations

This cleans up the previous implementation by providing a simpler check
in `surrounding_markers`, instead of calling a new function in
`expand_object`. No functionality was changed there except for handling
the empty selection and removing some cursor adjustments that should not
have been there after further testing.

Release Notes:

- N/A
This commit is contained in:
5brian 2025-02-24 20:30:21 -05:00 committed by GitHub
parent 980e1b533f
commit 52f73e0c2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 56 additions and 109 deletions

View file

@ -58,18 +58,18 @@ impl Vim {
self.update_editor(window, cx, |vim, editor, window, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
let mut original_positions: HashMap<_, _> = Default::default();
let mut start_positions: HashMap<_, _> = Default::default();
editor.change_selections(None, window, cx, |s| {
s.move_with(|map, selection| {
let original_position = (selection.head(), selection.goal);
object.expand_selection(map, selection, around);
original_positions.insert(selection.id, original_position);
let start_position = (selection.start, selection.goal);
start_positions.insert(selection.id, start_position);
});
});
vim.yank_selections_content(editor, false, cx);
editor.change_selections(None, window, cx, |s| {
s.move_with(|_, selection| {
let (head, goal) = original_positions.remove(&selection.id).unwrap();
let (head, goal) = start_positions.remove(&selection.id).unwrap();
selection.collapse_to(head, goal);
});
});