fix(events): handle bracketed paste in custom/search inputs

This commit is contained in:
SW 2026-07-16 12:38:26 +02:00
parent 498803fc55
commit 5906cddbbf
3 changed files with 34 additions and 2 deletions

2
Cargo.lock generated
View file

@ -825,7 +825,7 @@ dependencies = [
[[package]]
name = "lines"
version = "0.1.19"
version = "0.1.20"
dependencies = [
"base64",
"chrono",

View file

@ -1,6 +1,6 @@
[package]
name = "lines"
version = "0.1.19"
version = "0.1.20"
edition = "2024"
authors = ["janvete"]
description = "TUI for running frequently used commands"

View file

@ -11,6 +11,7 @@ pub enum AppEvent {
Tick,
Key(event::KeyEvent),
Mouse(event::MouseEvent),
Paste(String),
}
pub fn poll_event(timeout: Duration) -> io::Result<Option<AppEvent>> {
@ -18,6 +19,7 @@ pub fn poll_event(timeout: Duration) -> io::Result<Option<AppEvent>> {
match event::read()? {
Event::Key(key) => Ok(Some(AppEvent::Key(key))),
Event::Mouse(mouse) => Ok(Some(AppEvent::Mouse(mouse))),
Event::Paste(text) => Ok(Some(AppEvent::Paste(text))),
_ => Ok(Some(AppEvent::Tick)),
}
} else {
@ -50,6 +52,7 @@ pub fn handle_event(app: &mut App, event: AppEvent) -> bool {
}
_ => true,
},
AppEvent::Paste(text) => handle_paste_event(app, &text),
}
}
@ -239,6 +242,35 @@ fn pop_from_active_input(state: &mut CustomState) {
}
}
fn handle_paste_event(app: &mut App, text: &str) -> bool {
match app.screen {
Screen::Main => true,
Screen::Custom => {
let Some(state) = app.custom_state.as_mut() else {
app.exit_custom();
return true;
};
match state.focus {
CustomFocus::Input => state.command.push_str(text),
CustomFocus::PreCommand => state.pre_command.push_str(text),
CustomFocus::Lines => {}
}
true
}
Screen::Search => {
let Some(state) = app.search_state.as_mut() else {
app.exit_search();
return true;
};
// Search queries are single-line; keep only the first pasted line.
let query = text.lines().next().unwrap_or(text);
state.query.push_str(query);
app.update_search();
true
}
}
}
fn handle_search_event(app: &mut App, key: event::KeyEvent) -> bool {
let Some(state) = app.search_state.as_mut() else {
app.exit_search();