From 00808afe3c215d159574b23e30326379428060bf Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 1 Mar 2021 14:23:10 +0900 Subject: ui: Make editor more resilient about being shrunk too small. --- helix-term/src/ui/editor.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'helix-term/src/ui/editor.rs') 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 } } -- cgit v1.2.3-70-g09d2