Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Merge branch 'main' into vim-softwrap-word
Conrad Irwinaa7b65bbaf07
diff --cc crates/editor/src/movement.rsindex 915da7b23f8,75c4765fe3e..974af4bc240--- a/crates/editor/src/movement.rs+++ b/crates/editor/src/movement.rs@@@ -183,20 -177,20 +183,21 @@@ pub fn line_endpub fn previous_word_start(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {let raw_point = point.to_point(map);- let language = map.buffer_snapshot.language_at(raw_point);+ let scope = map.buffer_snapshot.language_scope_at(raw_point);- find_preceding_boundary(map, point, |left, right| {+ find_preceding_boundary(map, point, FindRange::MultiLine, |left, right| {- (char_kind(language, left) != char_kind(language, right) && !right.is_whitespace())+ (char_kind(&scope, left) != char_kind(&scope, right) && !right.is_whitespace())|| left == '\n'})}pub fn previous_subword_start(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {let raw_point = point.to_point(map);- let language = map.buffer_snapshot.language_at(raw_point);+ let scope = map.buffer_snapshot.language_scope_at(raw_point);- find_preceding_boundary(map, point, |left, right| {+++ find_preceding_boundary(map, point, FindRange::MultiLine, |left, right| {let is_word_start =- char_kind(language, left) != char_kind(language, right) && !right.is_whitespace();+ char_kind(&scope, left) != char_kind(&scope, right) && !right.is_whitespace();let is_subword_start =left == '_' && right != '_' || left.is_lowercase() && right.is_uppercase();is_word_start || is_subword_start || left == '\n'@@@ -205,19 -199,19 +206,21 @@@pub fn next_word_end(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {let raw_point = point.to_point(map);- let language = map.buffer_snapshot.language_at(raw_point);+ let scope = map.buffer_snapshot.language_scope_at(raw_point);- find_boundary(map, point, |left, right| {+++ find_boundary(map, point, FindRange::MultiLine, |left, right| {- (char_kind(language, left) != char_kind(language, right) && !left.is_whitespace())+ (char_kind(&scope, left) != char_kind(&scope, right) && !left.is_whitespace())|| right == '\n'})}pub fn next_subword_end(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {let raw_point = point.to_point(map);- let language = map.buffer_snapshot.language_at(raw_point);+ let scope = map.buffer_snapshot.language_scope_at(raw_point);- find_boundary(map, point, |left, right| {+++ find_boundary(map, point, FindRange::MultiLine, |left, right| {let is_word_end =- (char_kind(language, left) != char_kind(language, right)) && !left.is_whitespace();+ (char_kind(&scope, left) != char_kind(&scope, right)) && !left.is_whitespace();let is_subword_end =left != '_' && right == '_' || left.is_lowercase() && right.is_uppercase();is_word_end || is_subword_end || right == '\n'diff --cc crates/vim/src/motion.rsindex 6f28430796c,4c8560a5973..16bccb69633--- a/crates/vim/src/motion.rs+++ b/crates/vim/src/motion.rs@@@ -590,12 -589,12 +590,12 @@@ pub(crate) fn next_word_startignore_punctuation: bool,times: usize,) -> DisplayPoint {- let language = map.buffer_snapshot.language_at(point.to_point(map));+ let scope = map.buffer_snapshot.language_scope_at(point.to_point(map));for _ in 0..times {let mut crossed_newline = false;- point = movement::find_boundary(map, point, |left, right| {+ point = movement::find_boundary(map, point, FindRange::MultiLine, |left, right| {- let left_kind = char_kind(language, left).coerce_punctuation(ignore_punctuation);- let right_kind = char_kind(language, right).coerce_punctuation(ignore_punctuation);+ let left_kind = char_kind(&scope, left).coerce_punctuation(ignore_punctuation);+ let right_kind = char_kind(&scope, right).coerce_punctuation(ignore_punctuation);let at_newline = right == '\n';let found = (left_kind != right_kind && right_kind != CharKind::Whitespace)@@@ -615,18 -614,12 +615,17 @@@ fn next_word_endignore_punctuation: bool,times: usize,) -> DisplayPoint {- let language = map.buffer_snapshot.language_at(point.to_point(map));+ let scope = map.buffer_snapshot.language_scope_at(point.to_point(map));for _ in 0..times {- *point.column_mut() += 1;- point = movement::find_boundary(map, point, |left, right| {+ if point.column() < map.line_len(point.row()) {+ *point.column_mut() += 1;+ } else if point.row() < map.max_buffer_row() {+ *point.row_mut() += 1;+ *point.column_mut() = 0;+ }- // *point.column_mut() += 1;+ point = movement::find_boundary(map, point, FindRange::MultiLine, |left, right| {- let left_kind = char_kind(language, left).coerce_punctuation(ignore_punctuation);- let right_kind = char_kind(language, right).coerce_punctuation(ignore_punctuation);+ let left_kind = char_kind(&scope, left).coerce_punctuation(ignore_punctuation);+ let right_kind = char_kind(&scope, right).coerce_punctuation(ignore_punctuation);left_kind != right_kind && left_kind != CharKind::Whitespace});@@@ -656,13 -649,12 +655,13 @@@ fn previous_word_startfor _ in 0..times {// This works even though find_preceding_boundary is called for every character in the line containing// cursor because the newline is checked only once.- point = movement::find_preceding_boundary(map, point, |left, right| {- let left_kind = char_kind(&scope, left).coerce_punctuation(ignore_punctuation);- let right_kind = char_kind(&scope, right).coerce_punctuation(ignore_punctuation);+ point =+ movement::find_preceding_boundary(map, point, FindRange::MultiLine, |left, right| {- let left_kind = char_kind(language, left).coerce_punctuation(ignore_punctuation);- let right_kind = char_kind(language, right).coerce_punctuation(ignore_punctuation);++ let left_kind = char_kind(&scope, left).coerce_punctuation(ignore_punctuation);++ let right_kind = char_kind(&scope, right).coerce_punctuation(ignore_punctuation);- (left_kind != right_kind && !right.is_whitespace()) || left == '\n'- });+ (left_kind != right_kind && !right.is_whitespace()) || left == '\n'+ });}point}diff --cc crates/vim/src/normal/change.rsindex 6e64b050d1c,075ad5a6e87..836ce1492b6--- a/crates/vim/src/normal/change.rs+++ b/crates/vim/src/normal/change.rs@@@ -99,15 -96,12 +99,14 @@@ fn expand_changed_word_selection.unwrap_or_default();if in_word {- selection.end = movement::find_boundary(map, selection.end, |left, right| {- let left_kind = char_kind(&scope, left).coerce_punctuation(ignore_punctuation);- let right_kind = char_kind(&scope, right).coerce_punctuation(ignore_punctuation);+ selection.end =+ movement::find_boundary(map, selection.end, FindRange::MultiLine, |left, right| {- let left_kind =- char_kind(language, left).coerce_punctuation(ignore_punctuation);++ let left_kind = char_kind(&scope, left).coerce_punctuation(ignore_punctuation);+ let right_kind =- char_kind(language, right).coerce_punctuation(ignore_punctuation);++ char_kind(&scope, right).coerce_punctuation(ignore_punctuation);- left_kind != right_kind && left_kind != CharKind::Whitespace- });+ left_kind != right_kind && left_kind != CharKind::Whitespace+ });true} else {Motion::NextWordStart { ignore_punctuation }diff --cc crates/vim/src/object.rsindex 94906a1e800,d384948d170..653d4ca7b68--- a/crates/vim/src/object.rs+++ b/crates/vim/src/object.rs@@@ -182,19 -177,20 +182,22 @@@ fn in_wordignore_punctuation: bool,) -> Option<Range<DisplayPoint>> {// Use motion::right so that we consider the character under the cursor when looking for the start- let language = map.buffer_snapshot.language_at(relative_to.to_point(map));+ let scope = map+ .buffer_snapshot+ .language_scope_at(relative_to.to_point(map));- let start = movement::find_preceding_boundary_in_line(+ let start = movement::find_preceding_boundary(map,right(map, relative_to, 1),+ movement::FindRange::SingleLine,|left, right| {- char_kind(language, left).coerce_punctuation(ignore_punctuation)- != char_kind(language, right).coerce_punctuation(ignore_punctuation)+ char_kind(&scope, left).coerce_punctuation(ignore_punctuation)+ != char_kind(&scope, right).coerce_punctuation(ignore_punctuation)},);- let end = movement::find_boundary_in_line(map, relative_to, |left, right| {+++ let end = movement::find_boundary(map, relative_to, FindRange::SingleLine, |left, right| {- char_kind(language, left).coerce_punctuation(ignore_punctuation)- != char_kind(language, right).coerce_punctuation(ignore_punctuation)+ char_kind(&scope, left).coerce_punctuation(ignore_punctuation)+ != char_kind(&scope, right).coerce_punctuation(ignore_punctuation)});Some(start..end)@@@ -245,22 -243,23 +250,24 @@@ fn around_next_wordrelative_to: DisplayPoint,ignore_punctuation: bool,) -> Option<Range<DisplayPoint>> {- let language = map.buffer_snapshot.language_at(relative_to.to_point(map));+ let scope = map+ .buffer_snapshot+ .language_scope_at(relative_to.to_point(map));// Get the start of the word- let start = movement::find_preceding_boundary_in_line(+ let start = movement::find_preceding_boundary(map,right(map, relative_to, 1),+ FindRange::SingleLine,|left, right| {- char_kind(language, left).coerce_punctuation(ignore_punctuation)- != char_kind(language, right).coerce_punctuation(ignore_punctuation)+ char_kind(&scope, left).coerce_punctuation(ignore_punctuation)+ != char_kind(&scope, right).coerce_punctuation(ignore_punctuation)},);let mut word_found = false;- let end = movement::find_boundary(map, relative_to, |left, right| {+ let end = movement::find_boundary(map, relative_to, FindRange::MultiLine, |left, right| {- let left_kind = char_kind(language, left).coerce_punctuation(ignore_punctuation);- let right_kind = char_kind(language, right).coerce_punctuation(ignore_punctuation);+ let left_kind = char_kind(&scope, left).coerce_punctuation(ignore_punctuation);+ let right_kind = char_kind(&scope, right).coerce_punctuation(ignore_punctuation);let found = (word_found && left_kind != right_kind) || right == '\n' && left == '\n';