diff options
author | Blaž Hrastnik | 2020-10-07 05:06:25 +0000 |
---|---|---|
committer | GitHub | 2020-10-07 05:06:25 +0000 |
commit | 6848702b1f09dc1a4e8d2e3067d3b45b3421d403 (patch) | |
tree | 18cc823d2a5dfd0b09b5802f6eb11c978080df36 /helix-view/src/view.rs | |
parent | b7e1c0cf8253703a5eeb8453de23c8d0a6137ef1 (diff) | |
parent | 7f07e6676801be72e5a58b5612893c7d16f94a64 (diff) |
Merge pull request #3 from helix-editor/goto-implementation
Goto mode implementation
Diffstat (limited to 'helix-view/src/view.rs')
-rw-r--r-- | helix-view/src/view.rs | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 09cd4c65..887c45a2 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -11,7 +11,7 @@ use tui::layout::Rect; pub struct View { pub state: State, - pub first_line: u16, + pub first_line: usize, pub size: (u16, u16), pub theme: Theme, // TODO: share one instance } @@ -33,10 +33,10 @@ impl View { pub fn ensure_cursor_in_view(&mut self) { let cursor = self.state.selection().cursor(); - let line = self.state.doc().char_to_line(cursor) as u16; - let document_end = self.first_line + self.size.1.saturating_sub(1) - 1; + let line = self.state.doc().char_to_line(cursor); + let document_end = self.first_line + (self.size.1 as usize).saturating_sub(1); - let padding = 5u16; + let padding = 5usize; // TODO: side scroll @@ -51,9 +51,10 @@ impl View { /// Calculates the last visible line on screen #[inline] - pub fn last_line(&self, viewport: Rect) -> usize { + pub fn last_line(&self) -> usize { + let viewport = Rect::new(6, 0, self.size.0, self.size.1 - 1); // - 1 for statusline std::cmp::min( - (self.first_line + viewport.height) as usize, + self.first_line + (viewport.height as usize), self.state.doc().len_lines() - 1, ) } @@ -61,15 +62,10 @@ impl View { /// Translates a document position to an absolute position in the terminal. /// Returns a (line, col) position if the position is visible on screen. // TODO: Could return width as well for the character width at cursor. - pub fn screen_coords_at_pos( - &self, - text: &RopeSlice, - pos: usize, - viewport: Rect, - ) -> Option<Position> { + pub fn screen_coords_at_pos(&self, text: &RopeSlice, pos: usize) -> Option<Position> { let line = text.char_to_line(pos); - if line < self.first_line as usize || line > self.last_line(viewport) { + if line < self.first_line as usize || line > self.last_line() { // Line is not visible on screen return None; } |