mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Fix VIM cw on last character of a word doesn't work as expected: (#10963)
At the moment, using the default expand_selection seems to do the job well, without the need for some additional logic, which may also make the code a little clearer, Fix #10945 Release Notes: - N/A
This commit is contained in:
parent
d9d509a2bb
commit
5c2f27a501
@ -31,26 +31,19 @@ pub fn change_motion(vim: &mut Vim, motion: Motion, times: Option<usize>, cx: &m
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
motion_succeeded |= if let Motion::NextWordStart { ignore_punctuation } = motion
|
||||
{
|
||||
motion_succeeded |= match motion {
|
||||
Motion::NextWordStart { ignore_punctuation }
|
||||
| Motion::NextSubwordStart { ignore_punctuation } => {
|
||||
expand_changed_word_selection(
|
||||
map,
|
||||
selection,
|
||||
times,
|
||||
ignore_punctuation,
|
||||
&text_layout_details,
|
||||
false,
|
||||
motion == Motion::NextSubwordStart { ignore_punctuation },
|
||||
)
|
||||
} else if let Motion::NextSubwordStart { ignore_punctuation } = motion {
|
||||
expand_changed_word_selection(
|
||||
map,
|
||||
selection,
|
||||
times,
|
||||
ignore_punctuation,
|
||||
&text_layout_details,
|
||||
true,
|
||||
)
|
||||
} else {
|
||||
}
|
||||
_ => {
|
||||
let result = motion.expand_selection(
|
||||
map,
|
||||
selection,
|
||||
@ -72,7 +65,8 @@ pub fn change_motion(vim: &mut Vim, motion: Motion, times: Option<usize>, cx: &m
|
||||
selection.start = start_offset.to_display_point(map);
|
||||
}
|
||||
result
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
copy_selections_content(vim, editor, motion.linewise(), cx);
|
||||
@ -126,7 +120,7 @@ fn expand_changed_word_selection(
|
||||
text_layout_details: &TextLayoutDetails,
|
||||
use_subword: bool,
|
||||
) -> bool {
|
||||
if times.is_none() || times.unwrap() == 1 {
|
||||
let is_in_word = || {
|
||||
let scope = map
|
||||
.buffer_snapshot
|
||||
.language_scope_at(selection.start.to_point(map));
|
||||
@ -135,8 +129,17 @@ fn expand_changed_word_selection(
|
||||
.next()
|
||||
.map(|(c, _)| char_kind(&scope, c) != CharKind::Whitespace)
|
||||
.unwrap_or_default();
|
||||
|
||||
if in_word {
|
||||
return in_word;
|
||||
};
|
||||
if (times.is_none() || times.unwrap() == 1) && is_in_word() {
|
||||
let next_char = map
|
||||
.buffer_chars_at(
|
||||
motion::next_char(map, selection.end, false).to_offset(map, Bias::Left),
|
||||
)
|
||||
.next();
|
||||
match next_char {
|
||||
Some((' ', _)) => selection.end = motion::next_char(map, selection.end, false),
|
||||
_ => {
|
||||
if use_subword {
|
||||
selection.end =
|
||||
motion::next_subword_end(map, selection.end, ignore_punctuation, 1, false);
|
||||
@ -145,15 +148,9 @@ fn expand_changed_word_selection(
|
||||
motion::next_word_end(map, selection.end, ignore_punctuation, 1, false);
|
||||
}
|
||||
selection.end = motion::next_char(map, selection.end, false);
|
||||
true
|
||||
} else {
|
||||
let motion = if use_subword {
|
||||
Motion::NextSubwordStart { ignore_punctuation }
|
||||
} else {
|
||||
Motion::NextWordStart { ignore_punctuation }
|
||||
};
|
||||
motion.expand_selection(map, selection, None, false, &text_layout_details)
|
||||
}
|
||||
}
|
||||
true
|
||||
} else {
|
||||
let motion = if use_subword {
|
||||
Motion::NextSubwordStart { ignore_punctuation }
|
||||
@ -209,6 +206,7 @@ mod test {
|
||||
cx.assert("Teˇst").await;
|
||||
cx.assert("Tˇest test").await;
|
||||
cx.assert("Testˇ test").await;
|
||||
cx.assert("Tesˇt test").await;
|
||||
cx.assert(indoc! {"
|
||||
Test teˇst
|
||||
test"})
|
||||
|
@ -10,6 +10,10 @@
|
||||
{"Key":"c"}
|
||||
{"Key":"w"}
|
||||
{"Get":{"state":"Testˇtest","mode":"Insert"}}
|
||||
{"Put":{"state":"Tesˇt test"}}
|
||||
{"Key":"c"}
|
||||
{"Key":"w"}
|
||||
{"Get":{"state":"Tesˇ test","mode":"Insert"}}
|
||||
{"Put":{"state":"Test teˇst\ntest"}}
|
||||
{"Key":"c"}
|
||||
{"Key":"w"}
|
||||
|
Loading…
Reference in New Issue
Block a user