Fix - being a word character for selections (#17171)

Co-Authored-By: Mikayla <mikayla@zed.dev>
Co-Authored-By: Nate <nate@zed.dev>

Closes #15606
Closes #13515

Release Notes:

- Fixes `-` being considered a word character for selections in some
languages

Co-authored-by: Mikayla <mikayla@zed.dev>
Co-authored-by: Nate <nate@zed.dev>
This commit is contained in:
Conrad Irwin 2024-08-30 12:34:23 -06:00 committed by GitHub
parent c0731bfa28
commit ee6ec50b15
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 239 additions and 143 deletions

View file

@ -10,7 +10,7 @@ use editor::{
scroll::Autoscroll,
Bias, DisplayPoint,
};
use language::{char_kind, CharKind, Selection};
use language::Selection;
use ui::ViewContext;
impl Vim {
@ -59,13 +59,11 @@ impl Vim {
if let Motion::CurrentLine = motion {
let mut start_offset =
selection.start.to_offset(map, Bias::Left);
let scope = map
let classifier = map
.buffer_snapshot
.language_scope_at(selection.start.to_point(&map));
.char_classifier_at(selection.start.to_point(&map));
for (ch, offset) in map.buffer_chars_at(start_offset) {
if ch == '\n'
|| char_kind(&scope, ch) != CharKind::Whitespace
{
if ch == '\n' || !classifier.is_whitespace(ch) {
break;
}
start_offset = offset + ch.len_utf8();
@ -130,13 +128,13 @@ fn expand_changed_word_selection(
use_subword: bool,
) -> bool {
let is_in_word = || {
let scope = map
let classifier = map
.buffer_snapshot
.language_scope_at(selection.start.to_point(map));
.char_classifier_at(selection.start.to_point(map));
let in_word = map
.buffer_chars_at(selection.head().to_offset(map, Bias::Left))
.next()
.map(|(c, _)| char_kind(&scope, c) != CharKind::Whitespace)
.map(|(c, _)| !classifier.is_whitespace(c))
.unwrap_or_default();
return in_word;
};