From e41a786a77452468734b4f461d2144e8883ca3b2 Mon Sep 17 00:00:00 2001 From: Innes Anderson-Morrison Date: Thu, 19 Sep 2024 15:50:13 +0100 Subject: [PATCH] fix(ad): using the same dot expansion behaviour for keyboard loads as well as mouse --- src/buffer/mod.rs | 32 ++++++++++++++------------------ src/editor/mod.rs | 4 ++-- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index e576295..ae3cacd 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -656,34 +656,30 @@ impl Buffer { /// If the current dot is a cursor rather than a range, expand it to a sensible range. pub(crate) fn expand_cur_dot(&mut self) { if let Dot::Cur { .. } = self.dot { - self.set_dot(TextObject::Word, 1); + let mut min_dot = Find::expand(&FindDelimited::new('(', ')'), self.dot, self); + let candidates = [("[", "]"), ("<", ">"), ("{", "}"), (" \t\n", " \t\n")]; + + for (l, r) in candidates { + let dot = Find::expand(&FindDelimited::new(l, r), self.dot, self); + if dot.n_chars() < min_dot.n_chars() { + min_dot = dot; + } + } + + self.dot = min_dot; } } - pub(crate) fn expand_dot_from_screen_coords_if_outside_current_range( + pub(crate) fn set_dot_from_screen_coords_if_outside_current_range( &mut self, x: usize, y: usize, screen_rows: usize, ) { let mouse_cur = self.cur_from_screen_coords(x, y, screen_rows); - if self.dot.contains(&mouse_cur) { - return; - } - - self.set_dot_from_screen_coords(x, y, screen_rows); - - let mut min_dot = Find::expand(&FindDelimited::new('(', ')'), self.dot, self); - let candidates = [("[", "]"), ("<", ">"), ("{", "}"), (" \t\n", " \t\n")]; - - for (l, r) in candidates { - let dot = Find::expand(&FindDelimited::new(l, r), self.dot, self); - if dot.n_chars() < min_dot.n_chars() { - min_dot = dot; - } + if !self.dot.contains(&mouse_cur) { + self.set_dot_from_screen_coords(x, y, screen_rows); } - - self.dot = min_dot; } fn cur_from_screen_coords(&mut self, x: usize, y: usize, screen_rows: usize) -> Cur { diff --git a/src/editor/mod.rs b/src/editor/mod.rs index d8b54c9..5e2dd47 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -433,14 +433,14 @@ impl Editor { MouseEvent::Press { b: Right, x, y } => { self.buffers .active_mut() - .expand_dot_from_screen_coords_if_outside_current_range(x, y, self.screen_rows); + .set_dot_from_screen_coords_if_outside_current_range(x, y, self.screen_rows); self.default_load_dot(); } MouseEvent::Press { b: Middle, x, y } => { self.buffers .active_mut() - .expand_dot_from_screen_coords_if_outside_current_range(x, y, self.screen_rows); + .set_dot_from_screen_coords_if_outside_current_range(x, y, self.screen_rows); self.default_execute_dot(); }