Double click selects classified token, not highlight token

This commit is contained in:
Joshua Barretto 2026-01-05 12:37:34 +00:00
parent 30887458d8
commit 7fac2e4124
2 changed files with 19 additions and 18 deletions

View file

@ -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

View file

@ -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
}
}