Fixed autoscroll jump on 4-click

This commit is contained in:
Mikayla Maki 2022-09-19 17:05:10 -07:00
parent b3fafec20c
commit e0635a3ed8

View file

@ -1575,17 +1575,20 @@ impl Editor {
let start; let start;
let end; let end;
let mode; let mode;
let auto_scroll;
match click_count { match click_count {
1 => { 1 => {
start = buffer.anchor_before(position.to_point(&display_map)); start = buffer.anchor_before(position.to_point(&display_map));
end = start.clone(); end = start.clone();
mode = SelectMode::Character; mode = SelectMode::Character;
auto_scroll = true;
} }
2 => { 2 => {
let range = movement::surrounding_word(&display_map, position); let range = movement::surrounding_word(&display_map, position);
start = buffer.anchor_before(range.start.to_point(&display_map)); start = buffer.anchor_before(range.start.to_point(&display_map));
end = buffer.anchor_before(range.end.to_point(&display_map)); end = buffer.anchor_before(range.end.to_point(&display_map));
mode = SelectMode::Word(start.clone()..end.clone()); mode = SelectMode::Word(start.clone()..end.clone());
auto_scroll = true;
} }
3 => { 3 => {
let position = display_map let position = display_map
@ -1599,15 +1602,17 @@ impl Editor {
start = buffer.anchor_before(line_start); start = buffer.anchor_before(line_start);
end = buffer.anchor_before(next_line_start); end = buffer.anchor_before(next_line_start);
mode = SelectMode::Line(start.clone()..end.clone()); mode = SelectMode::Line(start.clone()..end.clone());
auto_scroll = true;
} }
_ => { _ => {
start = buffer.anchor_before(0); start = buffer.anchor_before(0);
end = buffer.anchor_before(buffer.len()); end = buffer.anchor_before(buffer.len());
mode = SelectMode::All; mode = SelectMode::All;
auto_scroll = false;
} }
} }
self.change_selections(Some(Autoscroll::Newest), cx, |s| { self.change_selections(auto_scroll.then(|| Autoscroll::Newest), cx, |s| {
if !add { if !add {
s.clear_disjoint(); s.clear_disjoint();
} else if click_count > 1 { } else if click_count > 1 {