vim: Command selection fixes (#18424)

Release Notes:

- vim: Fixed cursor position after `:{range}yank`.
- vim: Added `:fo[ld]`, `:foldo[pen]` and `:foldc[lose]`
This commit is contained in:
Conrad Irwin 2024-09-27 10:06:19 -06:00 committed by GitHub
parent 6d4ecac610
commit ffd1083cc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 220 additions and 104 deletions

View file

@ -1,4 +1,4 @@
use std::time::Duration;
use std::{ops::Range, time::Duration};
use crate::{
motion::Motion,
@ -73,7 +73,18 @@ impl Vim {
linewise: bool,
cx: &mut ViewContext<Editor>,
) {
self.copy_selections_content_internal(editor, linewise, true, cx);
self.copy_ranges(
editor,
linewise,
true,
editor
.selections
.all_adjusted(cx)
.iter()
.map(|s| s.range())
.collect(),
cx,
)
}
pub fn copy_selections_content(
@ -82,17 +93,28 @@ impl Vim {
linewise: bool,
cx: &mut ViewContext<Editor>,
) {
self.copy_selections_content_internal(editor, linewise, false, cx);
self.copy_ranges(
editor,
linewise,
false,
editor
.selections
.all_adjusted(cx)
.iter()
.map(|s| s.range())
.collect(),
cx,
)
}
fn copy_selections_content_internal(
pub(crate) fn copy_ranges(
&mut self,
editor: &mut Editor,
linewise: bool,
is_yank: bool,
selections: Vec<Range<Point>>,
cx: &mut ViewContext<Editor>,
) {
let selections = editor.selections.all_adjusted(cx);
let buffer = editor.buffer().read(cx).snapshot(cx);
let mut text = String::new();
let mut clipboard_selections = Vec::with_capacity(selections.len());