vim: Add support for :g/ and :v/ (#22177)

Closes #ISSUE

Still TODO to make this feature good is better command history

Release Notes:

- vim: Add support for `:g/<pattern>/<cmd>` and `:v/<pattern>/<cmd>`
This commit is contained in:
Conrad Irwin 2024-12-18 08:28:42 -07:00 committed by GitHub
parent 2ecbd97fe8
commit 4a6f071fde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 300 additions and 8 deletions

View file

@ -2,7 +2,7 @@ use std::sync::Arc;
use collections::HashMap;
use editor::{
display_map::{DisplaySnapshot, ToDisplayPoint},
display_map::{DisplayRow, DisplaySnapshot, ToDisplayPoint},
movement,
scroll::Autoscroll,
Bias, DisplayPoint, Editor, ToOffset,
@ -463,8 +463,16 @@ impl Vim {
*selection.end.column_mut() = map.line_len(selection.end.row())
} else if vim.mode != Mode::VisualLine {
selection.start = DisplayPoint::new(selection.start.row(), 0);
selection.end =
map.next_line_boundary(selection.end.to_point(map)).1;
if selection.end.row() == map.max_point().row() {
selection.end = map.max_point()
selection.end = map.max_point();
if selection.start == selection.end {
let prev_row =
DisplayRow(selection.start.row().0.saturating_sub(1));
selection.start =
DisplayPoint::new(prev_row, map.line_len(prev_row));
}
} else {
*selection.end.row_mut() += 1;
*selection.end.column_mut() = 0;