From 7fac2e41243170d397604c32bb2a22e841e551c0 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 5 Jan 2026 12:37:34 +0000 Subject: [PATCH] Double click selects classified token, not highlight token --- README.md | 2 +- src/state.rs | 35 ++++++++++++++++++----------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b9579c6..f8426f0 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,10 @@ - [ ] Terminal buffers - [ ] Matching delimiter highlighting - [ ] Ability to close buffers +- [ ] Tabbed sessions ## Issues to fix -- Double click should select ident, not highlighted token - Switcher search should allow searching whole path, not just parent - Scroll drag should work in opener preview - Switching buffers should preserve scroll position diff --git a/src/state.rs b/src/state.rs index 63c3b0a..eaf81e1 100644 --- a/src/state.rs +++ b/src/state.rs @@ -282,28 +282,29 @@ impl Buffer { } } - pub fn select_token_cursor(&mut self, cursor_id: CursorId) { + pub fn select_token_cursor(&mut self, cursor_id: CursorId) -> bool { let Some(cursor) = self.cursors.get_mut(cursor_id) else { - return; + return false; }; - let a = self.highlights.get_at(cursor.pos); - let b = self.highlights.get_at(cursor.pos.saturating_sub(1)); - if let Some(tok) = a - .zip(b) - .map(|(a, b)| { - if a.range.end - a.range.start > b.range.end - b.range.start { - a - } else { - b - } - }) - .or(a) - .or(b) + if let Some(class) = self + .text + .chars() + .get(cursor.pos) + .copied() + .and_then(classify) + && let start = (0..=cursor.pos) + .rev() + .find(|i| self.text.chars.get(*i).copied().and_then(classify) != Some(class)) + .map(|i| i + 1) + .unwrap_or(0) + && let Some(end) = (cursor.pos..) + .find(|i| self.text.chars.get(*i).copied().and_then(classify) != Some(class)) { - cursor.select(tok.range.clone()); + cursor.select(start..end); + true } else { - // TODO: Bell + false } }