diff options
author | Ivan Tham | 2021-06-08 16:40:38 +0000 |
---|---|---|
committer | Ivan Tham | 2021-06-10 03:08:18 +0000 |
commit | 6b3c9d8ed37fd36f8be8c217ec2c71fb73de63e7 (patch) | |
tree | 808da950ea2dbbda4bd030f0dacc029d2816e921 /helix-view/src | |
parent | 4dbc23ff1ca0c3cc601c6ea011d4ec0a294dd7b2 (diff) |
Fix jump behavior, goto_implementation now jump
Better jump behavior since we override the first jump if it's on the
first document. At the same time, ctrl-i is now working with gd jumps.
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/view.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index b7bfaa17..7bd31305 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -37,17 +37,24 @@ impl JumpList { pub fn forward(&mut self, count: usize) -> Option<&Jump> { if self.current + count < self.jumps.len() { self.current += count; - return self.jumps.get(self.current); + self.jumps.get(self.current) + } else { + None } - None } - pub fn backward(&mut self, count: usize) -> Option<&Jump> { - if self.current.checked_sub(count).is_some() { - self.current -= count; - return self.jumps.get(self.current); + // 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.checked_sub(count) { + if self.current == self.jumps.len() { + let jump = (doc.id(), doc.selection(view_id).clone()); + self.push(jump); + } + self.current = current; + self.jumps.get(self.current) + } else { + None } - None } } |