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 <contact@christitus.com>
This commit is contained in:
cartercanedy 2024-09-18 19:00:09 -07:00 committed by GitHub
parent 04537216d4
commit 1ea326747a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View File

@ -8,7 +8,7 @@ use ratatui::{
layout::Rect, layout::Rect,
style::{Style, Stylize}, style::{Style, Stylize},
text::Line, text::Line,
widgets::{Block, Borders, List}, widgets::{Block, Borders, Clear, List},
Frame, Frame,
}; };
pub enum FloatingTextMode { pub enum FloatingTextMode {
@ -102,15 +102,14 @@ impl FloatContent for FloatingText {
.map(Line::from) .map(Line::from)
.collect(); .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 // Create list widget
let list = List::new(lines) let list = List::new(lines)
.block(Block::default()) .block(Block::default())
.highlight_style(Style::default().reversed()); .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 // Render the list inside the bordered area
frame.render_widget(list, inner_area); frame.render_widget(list, inner_area);
} }

View File

@ -114,9 +114,11 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) {
scope_name: "Search bar", scope_name: "Search bar",
hints: vec![Shortcut::new(vec!["Enter"], "Finish search")], hints: vec![Shortcut::new(vec!["Enter"], "Finish search")],
}, },
Focus::List => { Focus::List => {
let mut hints = Vec::new(); let mut hints = Vec::new();
hints.push(Shortcut::new(vec!["q", "CTRL-c"], "Exit linutil")); hints.push(Shortcut::new(vec!["q", "CTRL-c"], "Exit linutil"));
if state.at_root() { if state.at_root() {
hints.push(Shortcut::new(vec!["h", "Left", "Tab"], "Focus tab list")); hints.push(Shortcut::new(vec!["h", "Left", "Tab"], "Focus tab list"));
hints.push(get_list_item_shortcut(state)); 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!["Tab"], "Focus tab list"));
}; };
hints.push(Shortcut::new(vec!["k", "Up"], "Select item above")); 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!["j", "Down"], "Select item below"));
hints.push(Shortcut::new(vec!["t"], "Next theme")); hints.push(Shortcut::new(vec!["t"], "Next theme"));
hints.push(Shortcut::new(vec!["T"], "Previous theme")); hints.push(Shortcut::new(vec!["T"], "Previous theme"));
ShortcutList { ShortcutList {
scope_name: "Item list", scope_name: "Item list",
hints, hints,
} }
} }
Focus::TabList => ShortcutList { Focus::TabList => ShortcutList {
scope_name: "Tab list", scope_name: "Tab list",
hints: vec![ hints: vec![
@ -156,6 +161,7 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) {
Shortcut::new(vec!["T"], "Previous theme"), Shortcut::new(vec!["T"], "Previous theme"),
], ],
}, },
Focus::FloatingWindow(ref float) => float.get_shortcut_list(), Focus::FloatingWindow(ref float) => float.get_shortcut_list(),
} }
.draw(frame, area); .draw(frame, area);