From 5906cddbbf336f45babfc050667a1faca1b713ec Mon Sep 17 00:00:00 2001 From: SW Date: Thu, 16 Jul 2026 12:38:26 +0200 Subject: [PATCH] fix(events): handle bracketed paste in custom/search inputs --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/events.rs | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ac323f..ee09bbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -825,7 +825,7 @@ dependencies = [ [[package]] name = "lines" -version = "0.1.19" +version = "0.1.20" dependencies = [ "base64", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 7442007..20b391b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/events.rs b/src/events.rs index 3c0be0c..dc7a880 100644 --- a/src/events.rs +++ b/src/events.rs @@ -11,6 +11,7 @@ pub enum AppEvent { Tick, Key(event::KeyEvent), Mouse(event::MouseEvent), + Paste(String), } pub fn poll_event(timeout: Duration) -> io::Result> { @@ -18,6 +19,7 @@ pub fn poll_event(timeout: Duration) -> io::Result> { 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();