@@ -61,8 +61,7 @@ impl JumpList {
6161pub struct View {
6262 pub id: ViewId,
6363 pub doc: DocumentId,
64− pub first_line: usize,
65− pub first_col: usize,
64+ pub offset: Position,
6665 pub area: Rect,
6766 pub jumps: JumpList,
6867 /// the last accessed file before the current one
@@ -74,8 +73,7 @@ impl View {
7473 Self {
7574 id: ViewId::default(),
7675 doc,
77− first_line: 0,
78− first_col: 0,
76+ offset: Position::new(0, 0),
7977 area: Rect::default(), // will get calculated upon inserting into tree
8078 jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
8179 last_accessed_doc: None,
@@ -91,7 +89,7 @@ impl View {
9189 let line = pos.row;
9290 let col = pos.col;
9391 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);
9593
9694 // - 1 so we have at least one gap in the middle.
9795 // 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 {
10098
10199 // TODO: not ideal
102100 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);
104102
105103 if line > last_line.saturating_sub(scrolloff) {
106104 // scroll down
107− self.first_line += line - (last_line.saturating_sub(scrolloff));
108− } else if line < self.first_line + scrolloff {
105+ self.offset.row += line - (last_line.saturating_sub(scrolloff));
106+ } else if line < self.offset.row + scrolloff {
109107 // scroll up
110− self.first_line = line.saturating_sub(scrolloff);
108+ self.offset.row = line.saturating_sub(scrolloff);
111109 }
112110
113111 if col > last_col.saturating_sub(scrolloff) {
114112 // scroll right
115− self.first_col += col - (last_col.saturating_sub(scrolloff));
116− } else if col < self.first_col + scrolloff {
113+ self.offset.col += col - (last_col.saturating_sub(scrolloff));
114+ } else if col < self.offset.col + scrolloff {
117115 // scroll left
118− self.first_col = col.saturating_sub(scrolloff);
116+ self.offset.col = col.saturating_sub(scrolloff);
119117 }
120118 }
121119
@@ -125,7 +123,7 @@ impl View {
125123 let height = self.area.height.saturating_sub(1); // - 1 for statusline
126124 std::cmp::min(
127125 // 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),
129127 doc.text().len_lines().saturating_sub(1),
130128 )
131129 }
@@ -141,7 +139,7 @@ impl View {
141139 ) -> Option<Position> {
142140 let line = text.char_to_line(pos);
143141
144− if line < self.first_line || line > self.last_line(doc) {
142+ if line < self.offset.row || line > self.last_line(doc) {
145143 // Line is not visible on screen
146144 return None;
147145 }
@@ -161,8 +159,8 @@ impl View {
161159 }
162160
163161 // 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);
165− let col = col.saturating_sub(self.first_col);
162+ let row = line.saturating_sub(self.offset.row);
163+ let col = col.saturating_sub(self.offset.col);
166164
167165 Some(Position::new(row, col))
168166 }
@@ -186,7 +184,7 @@ impl View {
186184 return None;
187185 }
188186
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;
190188
191189 if line_number > text.len_lines() - 1 {
192190 return Some(text.len_chars());
@@ -196,7 +194,7 @@ impl View {
196194
197195 let current_line = text.line(line_number);
198196
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;
200198 let mut selected = 0;
201199
202200 for grapheme in RopeGraphemes::new(current_line) {