vim: Fix Y on last line (#2975)
For zed-industries/community#2044 Release Notes: - vim: Fix y in VISUAL LINE mode when last line has no trailing newline ([#2044](https://github.com/zed-industries/community/issues/2044)).
This commit is contained in:
commit
5c22e40e99
4 changed files with 29 additions and 3 deletions
|
@ -455,6 +455,7 @@
|
||||||
"shift-d": "vim::VisualDelete",
|
"shift-d": "vim::VisualDelete",
|
||||||
"shift-x": "vim::VisualDelete",
|
"shift-x": "vim::VisualDelete",
|
||||||
"y": "vim::VisualYank",
|
"y": "vim::VisualYank",
|
||||||
|
"shift-y": "vim::VisualYank",
|
||||||
"p": "vim::Paste",
|
"p": "vim::Paste",
|
||||||
"shift-p": [
|
"shift-p": [
|
||||||
"vim::Paste",
|
"vim::Paste",
|
||||||
|
|
|
@ -26,10 +26,11 @@ pub fn copy_selections_content(editor: &mut Editor, linewise: bool, cx: &mut App
|
||||||
let is_last_line = linewise
|
let is_last_line = linewise
|
||||||
&& end.row == buffer.max_buffer_row()
|
&& end.row == buffer.max_buffer_row()
|
||||||
&& buffer.max_point().column > 0
|
&& buffer.max_point().column > 0
|
||||||
|
&& start.row < buffer.max_buffer_row()
|
||||||
&& start == Point::new(start.row, buffer.line_len(start.row));
|
&& start == Point::new(start.row, buffer.line_len(start.row));
|
||||||
|
|
||||||
if is_last_line {
|
if is_last_line {
|
||||||
start = Point::new(buffer.max_buffer_row(), 0);
|
start = Point::new(start.row + 1, 0);
|
||||||
}
|
}
|
||||||
for chunk in buffer.text_for_range(start..end) {
|
for chunk in buffer.text_for_range(start..end) {
|
||||||
text.push_str(chunk);
|
text.push_str(chunk);
|
||||||
|
|
|
@ -12,7 +12,7 @@ use language::{Selection, SelectionGoal};
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
motion::Motion,
|
motion::{start_of_line, Motion},
|
||||||
object::Object,
|
object::Object,
|
||||||
state::{Mode, Operator},
|
state::{Mode, Operator},
|
||||||
utils::copy_selections_content,
|
utils::copy_selections_content,
|
||||||
|
@ -326,7 +326,10 @@ pub fn yank(_: &mut Workspace, _: &VisualYank, cx: &mut ViewContext<Workspace>)
|
||||||
let line_mode = editor.selections.line_mode;
|
let line_mode = editor.selections.line_mode;
|
||||||
copy_selections_content(editor, line_mode, cx);
|
copy_selections_content(editor, line_mode, cx);
|
||||||
editor.change_selections(None, cx, |s| {
|
editor.change_selections(None, cx, |s| {
|
||||||
s.move_with(|_, selection| {
|
s.move_with(|map, selection| {
|
||||||
|
if line_mode {
|
||||||
|
selection.start = start_of_line(map, false, selection.start);
|
||||||
|
};
|
||||||
selection.collapse_to(selection.start, SelectionGoal::None)
|
selection.collapse_to(selection.start, SelectionGoal::None)
|
||||||
});
|
});
|
||||||
if vim.state().mode == Mode::VisualBlock {
|
if vim.state().mode == Mode::VisualBlock {
|
||||||
|
@ -672,6 +675,21 @@ mod test {
|
||||||
the lazy dog"})
|
the lazy dog"})
|
||||||
.await;
|
.await;
|
||||||
cx.assert_clipboard_content(Some("The q"));
|
cx.assert_clipboard_content(Some("The q"));
|
||||||
|
|
||||||
|
cx.set_shared_state(indoc! {"
|
||||||
|
The quick brown
|
||||||
|
fox ˇjumps over
|
||||||
|
the lazy dog"})
|
||||||
|
.await;
|
||||||
|
cx.simulate_shared_keystrokes(["shift-v", "shift-g", "shift-y"])
|
||||||
|
.await;
|
||||||
|
cx.assert_shared_state(indoc! {"
|
||||||
|
The quick brown
|
||||||
|
ˇfox jumps over
|
||||||
|
the lazy dog"})
|
||||||
|
.await;
|
||||||
|
cx.assert_shared_clipboard("fox jumps over\nthe lazy dog\n")
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
|
|
@ -27,3 +27,9 @@
|
||||||
{"Key":"k"}
|
{"Key":"k"}
|
||||||
{"Key":"y"}
|
{"Key":"y"}
|
||||||
{"Get":{"state":"ˇThe quick brown\nfox jumps over\nthe lazy dog","mode":"Normal"}}
|
{"Get":{"state":"ˇThe quick brown\nfox jumps over\nthe lazy dog","mode":"Normal"}}
|
||||||
|
{"Put":{"state":"The quick brown\nfox ˇjumps over\nthe lazy dog"}}
|
||||||
|
{"Key":"shift-v"}
|
||||||
|
{"Key":"shift-g"}
|
||||||
|
{"Key":"shift-y"}
|
||||||
|
{"Get":{"state":"The quick brown\nˇfox jumps over\nthe lazy dog","mode":"Normal"}}
|
||||||
|
{"ReadRegister":{"name":"\"","value":"fox jumps over\nthe lazy dog\n"}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue