From af7cdefc2b6586a84214258941097c07cc6bb338 Mon Sep 17 00:00:00 2001 From: Kyle Smith Date: Tue, 31 Jan 2023 18:31:42 -0500 Subject: [PATCH] Revert jumplist index changes. --- helix-view/src/view.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index cfbc85e9c..abcf9a169 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -21,21 +21,18 @@ type Jump = (DocumentId, Selection); #[derive(Debug, Clone)] pub struct JumpList { jumps: VecDeque, - current_idx: usize, + current: usize, } impl JumpList { pub fn new(initial: Jump) -> Self { let mut jumps = VecDeque::with_capacity(JUMP_LIST_CAPACITY); jumps.push_back(initial); - Self { - jumps, - current_idx: 0, - } + Self { jumps, current: 0 } } pub fn push(&mut self, jump: Jump) { - self.jumps.truncate(self.current_idx + 1); + self.jumps.truncate(self.current); // don't push duplicates if self.jumps.back() != Some(&jump) { // If the jumplist is full, drop the oldest item. @@ -44,14 +41,14 @@ impl JumpList { } self.jumps.push_back(jump); - self.current_idx = self.jumps.len() - 1; + self.current = self.jumps.len(); } } pub fn forward(&mut self, count: usize) -> Option<&Jump> { - if self.current_idx + count < self.jumps.len() { - self.current_idx += count; - self.jumps.get(self.current_idx) + if self.current + count < self.jumps.len() { + self.current += count; + self.jumps.get(self.current) } else { None } @@ -59,13 +56,13 @@ impl JumpList { // Taking view and doc to prevent unnecessary cloning when jump is not required. pub fn backward(&mut self, view_id: ViewId, doc: &mut Document, count: usize) -> Option<&Jump> { - if let Some(current) = self.current_idx.checked_sub(count) { - if self.current_idx == self.jumps.len() { + if let Some(current) = self.current.checked_sub(count) { + if self.current == self.jumps.len() { let jump = (doc.id(), doc.selection(view_id).clone()); self.push(jump); } - self.current_idx = current; - self.jumps.get(self.current_idx) + self.current = current; + self.jumps.get(self.current) } else { None }