From 0eb26d29eec8263388f6260deab07e33ce592c86 Mon Sep 17 00:00:00 2001 From: Krzysztof Witkowski Date: Mon, 1 Jul 2024 23:58:10 +0200 Subject: [PATCH] Fix auto-rename ranges with special characters (#13719) Release Notes: - Fixed ([#13551](https://github.com/zed-industries/zed/issues/13551)). --- crates/editor/src/editor.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index e534df3d65..951a41f9dd 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -3123,14 +3123,24 @@ impl Editor { let anchor = snapshot.anchor_after(selection.end); if !self.linked_edit_ranges.is_empty() { let start_anchor = snapshot.anchor_before(selection.start); - if let Some(ranges) = - self.linked_editing_ranges_for(start_anchor.text_anchor..anchor.text_anchor, cx) - { - for (buffer, edits) in ranges { - linked_edits - .entry(buffer.clone()) - .or_default() - .extend(edits.into_iter().map(|range| (range, text.clone()))); + + let is_word_char = text.chars().next().map_or(true, |char| { + let scope = snapshot.language_scope_at(start_anchor.to_offset(&snapshot)); + let kind = char_kind(&scope, char); + + kind == CharKind::Word + }); + + if is_word_char { + if let Some(ranges) = self + .linked_editing_ranges_for(start_anchor.text_anchor..anchor.text_anchor, cx) + { + for (buffer, edits) in ranges { + linked_edits + .entry(buffer.clone()) + .or_default() + .extend(edits.into_iter().map(|range| (range, text.clone()))); + } } } }