[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.
This commit is contained in:
parent
aa4bf8aea6
commit
dd55d7fc5f
@ -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.
|
// Handle events for all components.
|
||||||
let action = match self.last_active {
|
let action = match self.last_active {
|
||||||
@ -231,13 +237,6 @@ impl<'a> Component for App<'a> {
|
|||||||
AppExplorer => self.explorer.handle_event(event)?,
|
AppExplorer => self.explorer.handle_event(event)?,
|
||||||
AppLogger => self.logger.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 {
|
match action {
|
||||||
Action::Quit | Action::Handled => return Ok(action),
|
Action::Quit | Action::Handled => return Ok(action),
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
@ -10,10 +10,6 @@ use ratatui::prelude::{Color, Style};
|
|||||||
use ratatui::widgets::{Block, Borders, Padding, Widget};
|
use ratatui::widgets::{Block, Borders, Padding, Widget};
|
||||||
use syntect::parsing::SyntaxSet;
|
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 struct Editor {
|
||||||
pub state: EditorState,
|
pub state: EditorState,
|
||||||
pub event_handler: EditorEventHandler,
|
pub event_handler: EditorEventHandler,
|
||||||
@ -46,6 +42,8 @@ impl Editor {
|
|||||||
.collect();
|
.collect();
|
||||||
self.file_path = Some(path.clone());
|
self.file_path = Some(path.clone());
|
||||||
self.state.lines = Lines::new(lines);
|
self.state.lines = Lines::new(lines);
|
||||||
|
self.state.cursor.row = 0;
|
||||||
|
self.state.cursor.col = 0;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user