Cleanup handling of surrounding word logic, fixing crash in editor::SelectAllMatches (#33353)
This reduces code complexity and avoids unnecessary roundtripping through `DisplayPoint`. Hopefully this doesn't cause behavior changes, but has one known behavior improvement: `clip_at_line_ends` logic caused `is_inside_word` to return false when on a word at the end of the line. In vim mode, this caused `select_all_matches` to not select words at the end of lines, and in some cases crashes due to not finding any selections. Closes #29823 Release Notes: - N/A
This commit is contained in:
parent
014f93008a
commit
96409965e4
4 changed files with 71 additions and 127 deletions
|
@ -4214,6 +4214,19 @@ impl MultiBufferSnapshot {
|
|||
self.diffs.values().any(|diff| !diff.is_empty())
|
||||
}
|
||||
|
||||
pub fn is_inside_word<T: ToOffset>(&self, position: T, for_completion: bool) -> bool {
|
||||
let position = position.to_offset(self);
|
||||
let classifier = self
|
||||
.char_classifier_at(position)
|
||||
.for_completion(for_completion);
|
||||
let next_char_kind = self.chars_at(position).next().map(|c| classifier.kind(c));
|
||||
let prev_char_kind = self
|
||||
.reversed_chars_at(position)
|
||||
.next()
|
||||
.map(|c| classifier.kind(c));
|
||||
prev_char_kind.zip(next_char_kind) == Some((CharKind::Word, CharKind::Word))
|
||||
}
|
||||
|
||||
pub fn surrounding_word<T: ToOffset>(
|
||||
&self,
|
||||
start: T,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue