@@ -166,38 +166,26 @@ impl View {
166 Some(Position::new(row, col))
166 Some(Position::new(row, col))
169− /// Verifies whether a screen position is inside the view
170− /// Returns true when position is inside the view
171− pub fn verify_screen_coords(&self, row: usize, column: usize) -> bool {
173− if row < self.area.y as usize || row > self.area.y as usize + self.area.height as usize - 2
179− const OFFSET: usize = 7; // 1 diagnostic + 5 linenr + 1 gutter
181− if column < self.area.x as usize + OFFSET
182− || column > self.area.x as usize + self.area.width as usize
189 pub fn text_pos_at_screen_coords(
169 pub fn text_pos_at_screen_coords(
191 text: &RopeSlice,
171 text: &RopeSlice,
192− row: usize,
172+ row: u16,
193− column: usize,
173+ column: u16,
194 tab_width: usize,
174 tab_width: usize,
195 ) -> Option<usize> {
175 ) -> Option<usize> {
196− if !self.verify_screen_coords(row, column) {
176+ // TODO: not ideal
177+ const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
180+ if row < self.area.top() || row > self.area.bottom().saturating_sub(2) {
197 return None;
181 return None;
184+ if column < self.area.left() + OFFSET || column > self.area.right() {
200− let line_number = row - self.area.y as usize + self.first_line;
188+ let line_number = (row - self.area.y) as usize + self.first_line;
202 if line_number > text.len_lines() - 1 {
190 if line_number > text.len_lines() - 1 {
203 return Some(text.len_chars());
191 return Some(text.len_chars());
@@ -207,10 +195,7 @@ impl View {
208 let current_line = text.line(line_number);
196 let current_line = text.line(line_number);
211− const OFFSET: usize = 7; // 1 diagnostic + 5 linenr + 1 gutter
213− let target = column - OFFSET - self.area.x as usize + self.first_col;
198+ let target = (column - OFFSET - self.area.x) as usize + self.first_col;
214 let mut selected = 0;
199 let mut selected = 0;
216 for grapheme in RopeGraphemes::new(current_line) {
201 for grapheme in RopeGraphemes::new(current_line) {
@@ -231,7 +216,7 @@ impl View {
232 /// Translates a screen position to position in the text document.
217 /// Translates a screen position to position in the text document.
233 /// Returns a usize typed position in bounds of the text if found in this view, None if out of view.
218 /// Returns a usize typed position in bounds of the text if found in this view, None if out of view.
234− pub fn pos_at_screen_coords(&self, doc: &Document, row: usize, column: usize) -> Option<usize> {
219+ pub fn pos_at_screen_coords(&self, doc: &Document, row: u16, column: u16) -> Option<usize> {
235 self.text_pos_at_screen_coords(&doc.text().slice(..), row, column, doc.tab_width())
220 self.text_pos_at_screen_coords(&doc.text().slice(..), row, column, doc.tab_width())
237 // pub fn traverse<F>(&self, text: RopeSlice, start: usize, end: usize, fun: F)
222 // pub fn traverse<F>(&self, text: RopeSlice, start: usize, end: usize, fun: F)