Skip to content

Commit

Permalink
fix(ad): using the same dot expansion behaviour for keyboard loads as…
Browse files Browse the repository at this point in the history
… well as mouse
  • Loading branch information
sminez committed Sep 19, 2024
1 parent d89abe6 commit e41a786
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
32 changes: 14 additions & 18 deletions src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit e41a786

Please sign in to comment.