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
2 changed files with 63 additions and 61 deletions
|
@ -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.set_clip_at_line_ends(false, cx);
|
||||||
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||||
s.move_with(|map, selection| {
|
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(
|
expand_changed_word_selection(
|
||||||
map,
|
map,
|
||||||
selection,
|
selection,
|
||||||
times,
|
times,
|
||||||
ignore_punctuation,
|
ignore_punctuation,
|
||||||
&text_layout_details,
|
&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(
|
let result = motion.expand_selection(
|
||||||
map,
|
map,
|
||||||
selection,
|
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);
|
selection.start = start_offset.to_display_point(map);
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
};
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
copy_selections_content(vim, editor, motion.linewise(), cx);
|
copy_selections_content(vim, editor, motion.linewise(), cx);
|
||||||
|
@ -126,7 +120,7 @@ fn expand_changed_word_selection(
|
||||||
text_layout_details: &TextLayoutDetails,
|
text_layout_details: &TextLayoutDetails,
|
||||||
use_subword: bool,
|
use_subword: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if times.is_none() || times.unwrap() == 1 {
|
let is_in_word = || {
|
||||||
let scope = map
|
let scope = map
|
||||||
.buffer_snapshot
|
.buffer_snapshot
|
||||||
.language_scope_at(selection.start.to_point(map));
|
.language_scope_at(selection.start.to_point(map));
|
||||||
|
@ -135,8 +129,17 @@ fn expand_changed_word_selection(
|
||||||
.next()
|
.next()
|
||||||
.map(|(c, _)| char_kind(&scope, c) != CharKind::Whitespace)
|
.map(|(c, _)| char_kind(&scope, c) != CharKind::Whitespace)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
return in_word;
|
||||||
if 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 {
|
if use_subword {
|
||||||
selection.end =
|
selection.end =
|
||||||
motion::next_subword_end(map, selection.end, ignore_punctuation, 1, false);
|
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);
|
motion::next_word_end(map, selection.end, ignore_punctuation, 1, false);
|
||||||
}
|
}
|
||||||
selection.end = motion::next_char(map, selection.end, 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 {
|
} else {
|
||||||
let motion = if use_subword {
|
let motion = if use_subword {
|
||||||
Motion::NextSubwordStart { ignore_punctuation }
|
Motion::NextSubwordStart { ignore_punctuation }
|
||||||
|
@ -209,6 +206,7 @@ mod test {
|
||||||
cx.assert("Teˇst").await;
|
cx.assert("Teˇst").await;
|
||||||
cx.assert("Tˇest test").await;
|
cx.assert("Tˇest test").await;
|
||||||
cx.assert("Testˇ test").await;
|
cx.assert("Testˇ test").await;
|
||||||
|
cx.assert("Tesˇt test").await;
|
||||||
cx.assert(indoc! {"
|
cx.assert(indoc! {"
|
||||||
Test teˇst
|
Test teˇst
|
||||||
test"})
|
test"})
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
{"Key":"c"}
|
{"Key":"c"}
|
||||||
{"Key":"w"}
|
{"Key":"w"}
|
||||||
{"Get":{"state":"Testˇtest","mode":"Insert"}}
|
{"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"}}
|
{"Put":{"state":"Test teˇst\ntest"}}
|
||||||
{"Key":"c"}
|
{"Key":"c"}
|
||||||
{"Key":"w"}
|
{"Key":"w"}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue