@@ -61,8 +61,7 @@ impl JumpList {
61pub struct View {
61pub struct View {
62 pub id: ViewId,
62 pub id: ViewId,
63 pub doc: DocumentId,
63 pub doc: DocumentId,
64− pub first_line: usize,
64+ pub offset: Position,
65− pub first_col: usize,
66 pub area: Rect,
65 pub area: Rect,
67 pub jumps: JumpList,
66 pub jumps: JumpList,
68 /// the last accessed file before the current one
67 /// the last accessed file before the current one
@@ -74,8 +73,7 @@ impl View {
75 id: ViewId::default(),
74 id: ViewId::default(),
77− first_line: 0,
76+ offset: Position::new(0, 0),
79 area: Rect::default(), // will get calculated upon inserting into tree
77 area: Rect::default(), // will get calculated upon inserting into tree
80 jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
78 jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
81 last_accessed_doc: None,
79 last_accessed_doc: None,
@@ -91,7 +89,7 @@ impl View {
91 let line = pos.row;
89 let line = pos.row;
92 let col = pos.col;
90 let col = pos.col;
93 let height = self.area.height.saturating_sub(1); // - 1 for statusline
91 let height = self.area.height.saturating_sub(1); // - 1 for statusline
94− let last_line = (self.first_line + height as usize).saturating_sub(1);
92+ let last_line = (self.offset.row + height as usize).saturating_sub(1);
96 // - 1 so we have at least one gap in the middle.
94 // - 1 so we have at least one gap in the middle.
97 // a height of 6 with padding of 3 on each side will keep shifting the view back and forth
95 // a height of 6 with padding of 3 on each side will keep shifting the view back and forth
@@ -100,22 +98,22 @@ impl View {
101 // TODO: not ideal
99 // TODO: not ideal
102 const OFFSET: usize = 7; // 1 diagnostic + 5 linenr + 1 gutter
100 const OFFSET: usize = 7; // 1 diagnostic + 5 linenr + 1 gutter
103− let last_col = (self.first_col + self.area.width as usize).saturating_sub(OFFSET + 1);
101+ let last_col = (self.offset.col + self.area.width as usize).saturating_sub(OFFSET + 1);
105 if line > last_line.saturating_sub(scrolloff) {
103 if line > last_line.saturating_sub(scrolloff) {
106 // scroll down
104 // scroll down
107− self.first_line += line - (last_line.saturating_sub(scrolloff));
105+ self.offset.row += line - (last_line.saturating_sub(scrolloff));
108− } else if line < self.first_line + scrolloff {
106+ } else if line < self.offset.row + scrolloff {
109 // scroll up
107 // scroll up
110− self.first_line = line.saturating_sub(scrolloff);
108+ self.offset.row = line.saturating_sub(scrolloff);
113 if col > last_col.saturating_sub(scrolloff) {
111 if col > last_col.saturating_sub(scrolloff) {
114 // scroll right
112 // scroll right
115− self.first_col += col - (last_col.saturating_sub(scrolloff));
113+ self.offset.col += col - (last_col.saturating_sub(scrolloff));
116− } else if col < self.first_col + scrolloff {
114+ } else if col < self.offset.col + scrolloff {
117 // scroll left
115 // scroll left
118− self.first_col = col.saturating_sub(scrolloff);
116+ self.offset.col = col.saturating_sub(scrolloff);
@@ -125,7 +123,7 @@ impl View {
125 let height = self.area.height.saturating_sub(1); // - 1 for statusline
123 let height = self.area.height.saturating_sub(1); // - 1 for statusline
126 std::cmp::min(
124 std::cmp::min(
127 // Saturating subs to make it inclusive zero indexing.
125 // Saturating subs to make it inclusive zero indexing.
128− (self.first_line + height as usize).saturating_sub(1),
126+ (self.offset.row + height as usize).saturating_sub(1),
129 doc.text().len_lines().saturating_sub(1),
127 doc.text().len_lines().saturating_sub(1),
@@ -141,7 +139,7 @@ impl View {
141 ) -> Option<Position> {
139 ) -> Option<Position> {
142 let line = text.char_to_line(pos);
140 let line = text.char_to_line(pos);
144− if line < self.first_line || line > self.last_line(doc) {
142+ if line < self.offset.row || line > self.last_line(doc) {
145 // Line is not visible on screen
143 // Line is not visible on screen
146 return None;
144 return None;
@@ -161,8 +159,8 @@ impl View {
163 // It is possible for underflow to occur if the buffer length is larger than the terminal width.
161 // It is possible for underflow to occur if the buffer length is larger than the terminal width.
164− let row = line.saturating_sub(self.first_line);
162+ let row = line.saturating_sub(self.offset.row);
165− let col = col.saturating_sub(self.first_col);
163+ let col = col.saturating_sub(self.offset.col);
167 Some(Position::new(row, col))
165 Some(Position::new(row, col))
@@ -186,7 +184,7 @@ impl View {
186 return None;
184 return None;
189− let line_number = (row - self.area.y) as usize + self.first_line;
187+ let line_number = (row - self.area.y) as usize + self.offset.row;
191 if line_number > text.len_lines() - 1 {
189 if line_number > text.len_lines() - 1 {
192 return Some(text.len_chars());
190 return Some(text.len_chars());
@@ -196,7 +194,7 @@ impl View {
197 let current_line = text.line(line_number);
195 let current_line = text.line(line_number);
199− let target = (column - OFFSET - self.area.x) as usize + self.first_col;
197+ let target = (column - OFFSET - self.area.x) as usize + self.offset.col;
200 let mut selected = 0;
198 let mut selected = 0;
202 for grapheme in RopeGraphemes::new(current_line) {
200 for grapheme in RopeGraphemes::new(current_line) {