@@ -5,17 +5,56 @@ use std::borrow::Cow;
55use crate::{Document, DocumentId, ViewId};
66use helix_core::{
77 graphemes::{grapheme_width, RopeGraphemes},
8− Position, RopeSlice,
8+ Position, RopeSlice, Selection,
99};
1010use tui::layout::Rect;
1111
1212pub const PADDING: usize = 5;
1313
14+type Jump = (DocumentId, Selection);
15+
16+pub struct JumpList {
17+ jumps: Vec<Jump>,
18+ current: usize,
19+}
20+
21+impl JumpList {
22+ pub fn new(initial: Jump) -> Self {
23+ Self {
24+ jumps: vec![initial],
25+ current: 0,
26+ }
27+ }
28+
29+ pub fn push(&mut self, jump: Jump) {
30+ self.jumps.truncate(self.current + 1);
31+ self.jumps.push(jump);
32+ self.current += 1;
33+ }
34+
35+ pub fn forward(&mut self, count: usize) -> Option<&Jump> {
36+ if self.current + count < self.jumps.len() {
37+ self.current += count;
38+ return self.jumps.get(self.current);
39+ }
40+ None
41+ }
42+
43+ pub fn backward(&mut self, count: usize) -> Option<&Jump> {
44+ if self.current.checked_sub(count).is_some() {
45+ self.current -= count;
46+ return self.jumps.get(self.current);
47+ }
48+ None
49+ }
50+}
51+
1452pub struct View {
1553 pub id: ViewId,
1654 pub doc: DocumentId,
1755 pub first_line: usize,
1856 pub area: Rect,
57+ pub jumps: JumpList,
1958}
2059
2160impl View {
@@ -25,6 +64,7 @@ impl View {
2564 doc,
2665 first_line: 0,
2766 area: Rect::default(), // will get calculated upon inserting into tree
67+ jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
2868 };
2969
3070 Ok(view)