From f9375f449c8b7bbf792c88b89903fe38d524f2e5 Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Sat, 21 Aug 2021 10:51:20 +0530 Subject: Refactor new Rect construction (#575) * Refactor new Rect construction Introduces methods that can be chained to construct new Rects out of pre-existing ones * Clamp x and y to edges in Rect chop methods * Rename Rect clipping functions--- helix-term/src/ui/editor.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 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 b0e6de3e..d01d08e8 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -108,13 +108,11 @@ impl EditorView { self.render_diagnostics(doc, view, inner, surface, theme); - let area = Rect::new( - view.area.x, - view.area.y + view.area.height.saturating_sub(1), - view.area.width, - 1, - ); - self.render_statusline(doc, view, area, surface, theme, is_focused); + let statusline_area = view + .area + .clip_top(view.area.height.saturating_sub(1)) + .clip_bottom(1); // -1 from bottom to remove commandline + self.render_statusline(doc, view, statusline_area, surface, theme, is_focused); } /// Get syntax highlights for a document in a view represented by the first line @@ -528,12 +526,7 @@ impl EditorView { let width = 80.min(viewport.width); let height = 15.min(viewport.height); paragraph.render( - Rect::new( - viewport.right() - width, - viewport.y as u16 + 1, - width, - height, - ), + Rect::new(viewport.right() - width, viewport.y + 1, width, height), surface, ); } @@ -572,7 +565,7 @@ impl EditorView { theme.get("ui.statusline.inactive") }; // statusline - surface.set_style(Rect::new(viewport.x, viewport.y, viewport.width, 1), style); + surface.set_style(viewport.with_height(1), style); if is_focused { surface.set_string(viewport.x + 1, viewport.y, mode, style); } @@ -1001,8 +994,7 @@ impl Component for EditorView { surface.set_style(area, cx.editor.theme.get("ui.background")); // if the terminal size suddenly changed, we need to trigger a resize - cx.editor - .resize(Rect::new(area.x, area.y, area.width, area.height - 1)); // - 1 to account for commandline + cx.editor.resize(area.clip_bottom(1)); // -1 from bottom for commandline for (view, is_focused) in cx.editor.tree.views() { let doc = cx.editor.document(view.doc).unwrap(); -- cgit v1.2.3-70-g09d2 From 59e0ceef8c764950199a7e6874e15150ba329af3 Mon Sep 17 00:00:00 2001 From: Kirawi Date: Sat, 21 Aug 2021 22:15:33 -0400 Subject: better panic messages for when you're missing selection scopes (#608) --- helix-term/src/ui/editor.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 d01d08e8..4da8bfd5 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -195,7 +195,9 @@ impl EditorView { .find_scope_index("diagnostic") .or_else(|| theme.find_scope_index("ui.cursor")) .or_else(|| theme.find_scope_index("ui.selection")) - .expect("no selection scope found!"); + .expect( + "at least one of the following scopes must be defined in the theme: `diagnostic`, `ui.cursor`, or `ui.selection`", + ); doc.diagnostics() .iter() @@ -220,7 +222,7 @@ impl EditorView { let selection_scope = theme .find_scope_index("ui.selection") - .expect("no selection scope found!"); + .expect("could not find `ui.selection` scope in the theme!"); let base_cursor_scope = theme .find_scope_index("ui.cursor") .unwrap_or(selection_scope); -- cgit v1.2.3-70-g09d2