diff options
author | Blaž Hrastnik | 2021-03-01 05:23:10 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-03-01 05:23:10 +0000 |
commit | 00808afe3c215d159574b23e30326379428060bf (patch) | |
tree | b9f4fdb9cf559e95340a625c7741e9dbcd31b41b /helix-term/src/ui/editor.rs | |
parent | 2c9b02039bac81cb32309bd0d4e2b08191356b9c (diff) |
ui: Make editor more resilient about being shrunk too small.
Diffstat (limited to 'helix-term/src/ui/editor.rs')
-rw-r--r-- | helix-term/src/ui/editor.rs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 32697a03..499d8021 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -42,7 +42,7 @@ impl EditorView { viewport.x + OFFSET, viewport.y, viewport.width - OFFSET, - viewport.height - 1, + viewport.height.saturating_sub(1), ); // - 1 for statusline self.render_buffer(view, area, surface, theme, is_focused); @@ -52,7 +52,7 @@ impl EditorView { let area = Rect::new( viewport.x, - viewport.y + viewport.height - 1, + viewport.y + viewport.height.saturating_sub(1), viewport.width, 1, ); @@ -433,14 +433,16 @@ impl Component for EditorView { // Mode::Insert => write!(stdout, "\x1B[6 q"), // mode => write!(stdout, "\x1B[2 q"), // }; - let view = editor.view(); - let cursor = view.doc.selection().cursor(); - - let mut pos = view - .screen_coords_at_pos(view.doc.text().slice(..), cursor) - .expect("Cursor is out of bounds."); - pos.col += view.area.x as usize + area.x as usize + OFFSET as usize; - pos.row += view.area.y as usize + area.y as usize; - Some(pos) + // let view = editor.view(); + // let cursor = view.doc.selection().cursor(); + + // if let Some(mut pos) = view.screen_coords_at_pos(view.doc.text().slice(..), cursor) { + // pos.col += view.area.x as usize + area.x as usize + OFFSET as usize; + // pos.row += view.area.y as usize + area.y as usize; + // return Some(pos); + // } + + // It's easier to just not render the cursor and use selection rendering instead. + None } } |