From 48541fb05a253eb5c939bed758a95d79a1219678 Mon Sep 17 00:00:00 2001 From: smit <0xtimsb@gmail.com> Date: Thu, 20 Feb 2025 15:40:37 +0530 Subject: [PATCH] editor: Ignore whitespaces in selection highlight (#25236) This PR prevents whitespace selections from being highlighted. Before: image After: image Release Notes: - Fixed an issue where whitespace selections were incorrectly highlighted. --- crates/editor/src/editor.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 074e4611aa526cb8739855be6476173c6880f531..6d88c2787dde13a8c1dbbbd1007d90fd36ef6355 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4720,9 +4720,13 @@ impl Editor { return None; } let buffer = editor.buffer().read(cx).snapshot(cx); + let query = buffer.text_for_range(selection.range()).collect::(); + if query.trim().is_empty() { + editor.clear_background_highlights::(cx); + return None; + } Some(cx.background_spawn(async move { let mut ranges = Vec::new(); - let query = buffer.text_for_range(selection.range()).collect::(); let selection_anchors = selection.range().to_anchors(&buffer); for range in [buffer.anchor_before(0)..buffer.anchor_after(buffer.len())] { for (search_buffer, search_range, excerpt_id) in