feat: scroll viewports with mouse wheel without moving the caret
This commit is contained in:
@@ -889,6 +889,7 @@ pub struct Editor {
|
||||
next_buffer_id: usize,
|
||||
jumps: VecDeque<JumpLocation>,
|
||||
jump_index: usize,
|
||||
caret_reveal_revision: u64,
|
||||
command_line: String,
|
||||
clipboard: Vec<String>,
|
||||
clipboard_mode: ClipboardMode,
|
||||
@@ -931,6 +932,7 @@ impl Editor {
|
||||
next_buffer_id: 2,
|
||||
jumps: VecDeque::new(),
|
||||
jump_index: 0,
|
||||
caret_reveal_revision: 0,
|
||||
command_line: String::new(),
|
||||
clipboard: Vec::new(),
|
||||
clipboard_mode: ClipboardMode::System,
|
||||
@@ -1329,6 +1331,7 @@ impl Editor {
|
||||
}
|
||||
|
||||
fn place_navigation(&mut self, position: TextPosition) {
|
||||
self.reveal_caret();
|
||||
self.park_source();
|
||||
self.active.mode = Mode::Normal;
|
||||
let row = position.row.min(self.active.lines.len() - 1);
|
||||
@@ -1422,6 +1425,14 @@ impl Editor {
|
||||
pub fn cursor(&self) -> Cursor {
|
||||
self.active.targets[self.active.primary].active
|
||||
}
|
||||
/// Navigation requests caret following even when its logical position stays unchanged.
|
||||
pub(crate) fn caret_reveal_revision(&self) -> u64 {
|
||||
self.caret_reveal_revision
|
||||
}
|
||||
|
||||
fn reveal_caret(&mut self) {
|
||||
self.caret_reveal_revision = self.caret_reveal_revision.wrapping_add(1);
|
||||
}
|
||||
pub fn mode(&self) -> Mode {
|
||||
self.active.mode
|
||||
}
|
||||
@@ -2580,6 +2591,7 @@ impl Editor {
|
||||
}
|
||||
|
||||
fn seek_search(&mut self, forward: bool, count: usize) {
|
||||
self.reveal_caret();
|
||||
let source = self.jump_location();
|
||||
self.active.search_match = None;
|
||||
if self.active.search_query.is_empty() {
|
||||
@@ -2671,6 +2683,7 @@ impl Editor {
|
||||
}
|
||||
|
||||
fn traverse_jumps(&mut self, forward: bool, count: usize) {
|
||||
self.reveal_caret();
|
||||
let departure = self.jump_location();
|
||||
let mut destination = departure;
|
||||
let mut index = self.jump_index;
|
||||
@@ -2752,6 +2765,7 @@ impl Editor {
|
||||
|
||||
fn switch_buffer(&mut self, id: usize) {
|
||||
if id == self.active.id {
|
||||
self.reveal_caret();
|
||||
self.park_source();
|
||||
self.show_buffer();
|
||||
} else if let Some(buffer) = self.parked.remove(&id) {
|
||||
@@ -3981,6 +3995,7 @@ impl Editor {
|
||||
}
|
||||
|
||||
fn move_targets(&mut self, action: Action, count: usize) {
|
||||
self.reveal_caret();
|
||||
for index in 0..self.active.targets.len() {
|
||||
let mut cursor = self.active.targets[index].active;
|
||||
match action {
|
||||
|
||||
Reference in New Issue
Block a user