From 1ea326747a9b54e5bf7bdd54e09d429600747d12 Mon Sep 17 00:00:00 2001 From: cartercanedy <99052281+cartercanedy@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:00:09 -0700 Subject: [PATCH] fix: Fixup preview rendering and logic of preview key binding being shown in shortcut list (#387) * always check if selection is a command if list is focused * clear float widget render area before rendering content * Update hint.rs * Update floating_text.rs Thanks to @jeevithakannan2 for idea --------- Co-authored-by: Chris Titus --- tui/src/floating_text.rs | 9 ++++----- tui/src/hint.rs | 6 ++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tui/src/floating_text.rs b/tui/src/floating_text.rs index fd53ed07..ad77c36f 100644 --- a/tui/src/floating_text.rs +++ b/tui/src/floating_text.rs @@ -8,7 +8,7 @@ use ratatui::{ layout::Rect, style::{Style, Stylize}, text::Line, - widgets::{Block, Borders, List}, + widgets::{Block, Borders, Clear, List}, Frame, }; pub enum FloatingTextMode { @@ -102,15 +102,14 @@ impl FloatContent for FloatingText { .map(Line::from) .collect(); - // Prevents background text from appearing after the floating content - while lines.len() < inner_area.height as usize { - lines.push(Line::from(" ".repeat(inner_area.width as usize))); - } // Create list widget let list = List::new(lines) .block(Block::default()) .highlight_style(Style::default().reversed()); + // Clear the text underneath the floats rendered area + frame.render_widget(Clear, inner_area); + // Render the list inside the bordered area frame.render_widget(list, inner_area); } diff --git a/tui/src/hint.rs b/tui/src/hint.rs index a1b924cd..00ac4fae 100644 --- a/tui/src/hint.rs +++ b/tui/src/hint.rs @@ -114,9 +114,11 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) { scope_name: "Search bar", hints: vec![Shortcut::new(vec!["Enter"], "Finish search")], }, + Focus::List => { let mut hints = Vec::new(); hints.push(Shortcut::new(vec!["q", "CTRL-c"], "Exit linutil")); + if state.at_root() { hints.push(Shortcut::new(vec!["h", "Left", "Tab"], "Focus tab list")); hints.push(get_list_item_shortcut(state)); @@ -136,15 +138,18 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) { } hints.push(Shortcut::new(vec!["Tab"], "Focus tab list")); }; + hints.push(Shortcut::new(vec!["k", "Up"], "Select item above")); hints.push(Shortcut::new(vec!["j", "Down"], "Select item below")); hints.push(Shortcut::new(vec!["t"], "Next theme")); hints.push(Shortcut::new(vec!["T"], "Previous theme")); + ShortcutList { scope_name: "Item list", hints, } } + Focus::TabList => ShortcutList { scope_name: "Tab list", hints: vec![ @@ -156,6 +161,7 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) { Shortcut::new(vec!["T"], "Previous theme"), ], }, + Focus::FloatingWindow(ref float) => float.get_shortcut_list(), } .draw(frame, area);