mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-25 01:34:02 +00:00
vim: Fix some dw edge cases
This commit is contained in:
parent
ece4875973
commit
768c991909
6 changed files with 75 additions and 28 deletions
|
@ -467,6 +467,22 @@ impl Motion {
|
|||
|
||||
(_, selection.end) = map.next_line_boundary(selection.end.to_point(map));
|
||||
} else {
|
||||
// Another special case: When using the "w" motion in combination with an
|
||||
// operator and the last word moved over is at the end of a line, the end of
|
||||
// that word becomes the end of the operated text, not the first word in the
|
||||
// next line.
|
||||
if let Motion::NextWordStart {
|
||||
ignore_punctuation: _,
|
||||
} = self
|
||||
{
|
||||
let start_row = selection.start.to_point(&map).row;
|
||||
if selection.end.to_point(&map).row > start_row {
|
||||
selection.end =
|
||||
Point::new(start_row, map.buffer_snapshot.line_len(start_row))
|
||||
.to_display_point(&map)
|
||||
}
|
||||
}
|
||||
|
||||
// If the motion is exclusive and the end of the motion is in column 1, the
|
||||
// end of the motion is moved to the end of the previous line and the motion
|
||||
// becomes inclusive. Example: "}" moves to the first line after a paragraph,
|
||||
|
|
|
@ -76,12 +76,6 @@ pub fn change_object(vim: &mut Vim, object: Object, around: bool, cx: &mut Windo
|
|||
// word does not include the following white space. {Vi: "cw" when on a blank
|
||||
// followed by other blanks changes only the first blank; this is probably a
|
||||
// bug, because "dw" deletes all the blanks}
|
||||
//
|
||||
// NOT HANDLED YET
|
||||
// Another special case: When using the "w" motion in combination with an
|
||||
// operator and the last word moved over is at the end of a line, the end of
|
||||
// that word becomes the end of the operated text, not the first word in the
|
||||
// next line.
|
||||
fn expand_changed_word_selection(
|
||||
map: &DisplaySnapshot,
|
||||
selection: &mut Selection<DisplayPoint>,
|
||||
|
|
|
@ -2,6 +2,7 @@ use crate::{motion::Motion, object::Object, utils::copy_selections_content, Vim}
|
|||
use collections::{HashMap, HashSet};
|
||||
use editor::{display_map::ToDisplayPoint, scroll::autoscroll::Autoscroll, Bias};
|
||||
use gpui::WindowContext;
|
||||
use language::Point;
|
||||
|
||||
pub fn delete_motion(vim: &mut Vim, motion: Motion, times: Option<usize>, cx: &mut WindowContext) {
|
||||
vim.stop_recording();
|
||||
|
@ -14,6 +15,27 @@ pub fn delete_motion(vim: &mut Vim, motion: Motion, times: Option<usize>, cx: &m
|
|||
let original_head = selection.head();
|
||||
original_columns.insert(selection.id, original_head.column());
|
||||
motion.expand_selection(map, selection, times, true);
|
||||
|
||||
// Motion::NextWordStart on an empty line should delete it.
|
||||
if let Motion::NextWordStart {
|
||||
ignore_punctuation: _,
|
||||
} = motion
|
||||
{
|
||||
if selection.is_empty()
|
||||
&& map
|
||||
.buffer_snapshot
|
||||
.line_len(selection.start.to_point(&map).row)
|
||||
== 0
|
||||
{
|
||||
selection.end = map
|
||||
.buffer_snapshot
|
||||
.clip_point(
|
||||
Point::new(selection.start.to_point(&map).row + 1, 0),
|
||||
Bias::Left,
|
||||
)
|
||||
.to_display_point(map)
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
copy_selections_content(editor, motion.linewise(), cx);
|
||||
|
@ -129,28 +151,44 @@ mod test {
|
|||
|
||||
#[gpui::test]
|
||||
async fn test_delete_w(cx: &mut gpui::TestAppContext) {
|
||||
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "w"]);
|
||||
cx.assert("Teˇst").await;
|
||||
cx.assert("Tˇest test").await;
|
||||
cx.assert(indoc! {"
|
||||
Test teˇst
|
||||
test"})
|
||||
.await;
|
||||
cx.assert(indoc! {"
|
||||
let mut cx = NeovimBackedTestContext::new(cx).await;
|
||||
cx.assert_neovim_compatible(
|
||||
indoc! {"
|
||||
Test tesˇt
|
||||
test"})
|
||||
test"},
|
||||
["d", "w"],
|
||||
)
|
||||
.await;
|
||||
cx.assert_exempted(
|
||||
|
||||
cx.assert_neovim_compatible("Teˇst", ["d", "w"]).await;
|
||||
cx.assert_neovim_compatible("Tˇest test", ["d", "w"]).await;
|
||||
cx.assert_neovim_compatible(
|
||||
indoc! {"
|
||||
Test teˇst
|
||||
test"},
|
||||
["d", "w"],
|
||||
)
|
||||
.await;
|
||||
cx.assert_neovim_compatible(
|
||||
indoc! {"
|
||||
Test tesˇt
|
||||
test"},
|
||||
["d", "w"],
|
||||
)
|
||||
.await;
|
||||
|
||||
cx.assert_neovim_compatible(
|
||||
indoc! {"
|
||||
Test test
|
||||
ˇ
|
||||
test"},
|
||||
ExemptionFeatures::DeleteWordOnEmptyLine,
|
||||
["d", "w"],
|
||||
)
|
||||
.await;
|
||||
|
||||
let mut cx = cx.binding(["d", "shift-w"]);
|
||||
cx.assert("Test teˇst-test test").await;
|
||||
cx.assert_neovim_compatible("Test teˇst-test test", ["d", "shift-w"])
|
||||
.await;
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
|
|
|
@ -23,8 +23,6 @@ pub enum ExemptionFeatures {
|
|||
// MOTIONS
|
||||
// When an operator completes at the end of the file, an extra newline is left
|
||||
OperatorLastNewlineRemains,
|
||||
// Deleting a word on an empty line doesn't remove the newline
|
||||
DeleteWordOnEmptyLine,
|
||||
|
||||
// OBJECTS
|
||||
// Resulting position after the operation is slightly incorrect for unintuitive reasons.
|
||||
|
|
|
@ -20,10 +20,3 @@
|
|||
{"Key":"0"}
|
||||
{"Key":"enter"}
|
||||
{"Get":{"state":"aa\ndd\nˇcc","mode":"Normal"}}
|
||||
{"Key":":"}
|
||||
{"Key":"%"}
|
||||
{"Key":"s"}
|
||||
{"Key":"/"}
|
||||
{"Key":"/"}
|
||||
{"Key":"/"}
|
||||
{"Key":"enter"}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
{"Put":{"state":"Test tesˇt\n test"}}
|
||||
{"Key":"d"}
|
||||
{"Key":"w"}
|
||||
{"Get":{"state":"Test teˇs\n test","mode":"Normal"}}
|
||||
{"Put":{"state":"Teˇst"}}
|
||||
{"Key":"d"}
|
||||
{"Key":"w"}
|
||||
|
@ -14,6 +18,10 @@
|
|||
{"Key":"d"}
|
||||
{"Key":"w"}
|
||||
{"Get":{"state":"Test teˇs\ntest","mode":"Normal"}}
|
||||
{"Put":{"state":"Test test\nˇ\ntest"}}
|
||||
{"Key":"d"}
|
||||
{"Key":"w"}
|
||||
{"Get":{"state":"Test test\nˇtest","mode":"Normal"}}
|
||||
{"Put":{"state":"Test teˇst-test test"}}
|
||||
{"Key":"d"}
|
||||
{"Key":"shift-w"}
|
||||
|
|
Loading…
Reference in a new issue