From da7f0780636643bf8325d9d97ce99113992987b5 Mon Sep 17 00:00:00 2001 From: afonsofrancof Date: Thu, 8 Aug 2024 23:37:19 +0100 Subject: [PATCH] Moved preview_content to floating_text and merged --- src/float.rs | 2 -- src/{preview_content.rs => floating_text.rs} | 0 src/list.rs | 4 +--- src/main.rs | 14 +++++++------- 4 files changed, 8 insertions(+), 12 deletions(-) rename src/{preview_content.rs => floating_text.rs} (100%) diff --git a/src/float.rs b/src/float.rs index 5048f1b8..cd0bd9f8 100644 --- a/src/float.rs +++ b/src/float.rs @@ -1,8 +1,6 @@ use crossterm::event::{KeyCode, KeyEvent}; use ratatui::{ layout::{Constraint, Direction, Layout, Rect}, - style::{Color, Style, Stylize}, - widgets::Block, Frame, }; diff --git a/src/preview_content.rs b/src/floating_text.rs similarity index 100% rename from src/preview_content.rs rename to src/floating_text.rs diff --git a/src/list.rs b/src/list.rs index c6897397..a750f393 100644 --- a/src/list.rs +++ b/src/list.rs @@ -1,6 +1,4 @@ -use crate::{ - float::Float, preview_content::FloatingText, running_command::Command, state::AppState, -}; +use crate::{float::Float, floating_text::FloatingText, running_command::Command, state::AppState}; use crossterm::event::{KeyCode, KeyEvent, KeyEventKind}; use ego_tree::{tree, NodeId}; use ratatui::{ diff --git a/src/main.rs b/src/main.rs index ee104b1f..f7ae28ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ mod float; +mod floating_text; mod list; -mod preview_content; mod running_command; pub mod state; mod theme; @@ -140,11 +140,11 @@ fn run(terminal: &mut Terminal, state: &AppState) -> io::Result<( if key.kind != KeyEventKind::Press && key.kind != KeyEventKind::Repeat { continue; } - if let Some(ref mut command) = command_opt { - if command.handle_key_event(&key) { - command_opt = None; - } - } else { + + //Send the key to the float + //If we receive true, then the float processed the input + //If that's the case, don't propagate input to other widgets + if !command_float.handle_key_event(&key) { //Insert user input into the search bar if in_search_mode { match key.code { @@ -168,7 +168,7 @@ fn run(terminal: &mut Terminal, state: &AppState) -> io::Result<( _ => {} } } else if let Some(cmd) = custom_list.handle_key(key, state) { - command_opt = Some(RunningCommand::new(cmd, state)); + command_float.set_content(Some(RunningCommand::new(cmd, state))); } else { // Handle keys while not in search mode match key.code {