Fix zed-industries/community#1950 (#2892)

Release Notes:

- vim: fix goal preservation of visual block selections
([#1950](https://github.com/zed-industries/community/issues/1950)).
This commit is contained in:
Conrad Irwin 2023-08-25 11:55:48 -06:00 committed by GitHub
commit 1c945a7521
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 9 deletions

View File

@ -126,10 +126,15 @@ pub fn visual_block_motion(
let map = &s.display_map();
let mut head = s.newest_anchor().head().to_display_point(map);
let mut tail = s.oldest_anchor().tail().to_display_point(map);
let mut goal = s.newest_anchor().goal;
let (start, end) = match s.newest_anchor().goal {
SelectionGoal::ColumnRange { start, end } if preserve_goal => (start, end),
SelectionGoal::Column(start) if preserve_goal => (start, start + 1),
_ => (tail.column(), head.column()),
};
let goal = SelectionGoal::ColumnRange { start, end };
let was_reversed = tail.column() > head.column();
if !was_reversed && !preserve_goal {
head = movement::saturating_left(map, head);
}
@ -149,13 +154,6 @@ pub fn visual_block_motion(
head = movement::saturating_right(map, head)
}
let (start, end) = match goal {
SelectionGoal::ColumnRange { start, end } if preserve_goal => (start, end),
SelectionGoal::Column(start) if preserve_goal => (start, start + 1),
_ => (tail.column(), head.column()),
};
goal = SelectionGoal::ColumnRange { start, end };
let columns = if is_reversed {
head.column()..tail.column()
} else if head.column() == tail.column() {
@ -791,6 +789,26 @@ mod test {
"
})
.await;
//https://github.com/zed-industries/community/issues/1950
cx.set_shared_state(indoc! {
"Theˇ quick brown
fox jumps over
the lazy dog
"
})
.await;
cx.simulate_shared_keystrokes(["l", "ctrl-v", "j", "j"])
.await;
cx.assert_shared_state(indoc! {
"The «qˇ»uick brown
fox «»umps over
the lazy dog
"
})
.await;
}
#[gpui::test]

View File

@ -30,3 +30,9 @@
{"Key":"o"}
{"Key":"escape"}
{"Get":{"state":"Theˇouick\nbroo\nfoxo\njumo over the\n\nlazy dog\n","mode":"Normal"}}
{"Put":{"state":"Theˇ quick brown\n\nfox jumps over\nthe lazy dog\n"}}
{"Key":"l"}
{"Key":"ctrl-v"}
{"Key":"j"}
{"Key":"j"}
{"Get":{"state":"The «qˇ»uick brown\n\nfox «jˇ»umps over\nthe lazy dog\n","mode":"VisualBlock"}}