From dd55d7fc5fb3a991bc334085d7a47d14f8b21c1c Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sat, 24 Jan 2026 12:47:17 -0500 Subject: [PATCH] [tui] Handle mouse input for all widgets. This way you can still click to interact with the file explorer while editing a file, for example, without changing widget focus. --- src/tui/app.rs | 13 ++++++------- src/tui/editor.rs | 6 ++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/tui/app.rs b/src/tui/app.rs index bc97bb0..db339ef 100644 --- a/src/tui/app.rs +++ b/src/tui/app.rs @@ -224,6 +224,12 @@ impl<'a> Component for App<'a> { _ => {} } } + // Components should always handle mouse events for click interaction. + if let Some(mouse) = event.as_mouse_event() { + self.editor.handle_mouse_events(mouse)?; + self.explorer.handle_mouse_events(mouse)?; + self.logger.handle_mouse_events(mouse)?; + } // Handle events for all components. let action = match self.last_active { @@ -231,13 +237,6 @@ impl<'a> Component for App<'a> { AppExplorer => self.explorer.handle_event(event)?, AppLogger => self.logger.handle_event(event)?, }; - // if !c.is_active() { - // if let Some(mouse) = event.as_mouse_event() { - // // Always handle mouse events for click interaction. - // c.handle_mouse_events(mouse)?; - // } - // continue; - // } match action { Action::Quit | Action::Handled => return Ok(action), _ => {} diff --git a/src/tui/editor.rs b/src/tui/editor.rs index 6db9759..c49abea 100644 --- a/src/tui/editor.rs +++ b/src/tui/editor.rs @@ -10,10 +10,6 @@ use ratatui::prelude::{Color, Style}; use ratatui::widgets::{Block, Borders, Padding, Widget}; use syntect::parsing::SyntaxSet; -// TODO: Consider using editor-command https://docs.rs/editor-command/latest/editor_command/ -// TODO: Title should be detected programming language name -// TODO: Content should be file contents -// TODO: Vimrc should be used pub struct Editor { pub state: EditorState, pub event_handler: EditorEventHandler, @@ -46,6 +42,8 @@ impl Editor { .collect(); self.file_path = Some(path.clone()); self.state.lines = Lines::new(lines); + self.state.cursor.row = 0; + self.state.cursor.col = 0; } Ok(()) }