fix(events): handle bracketed paste in custom/search inputs
This commit is contained in:
parent
498803fc55
commit
5906cddbbf
3 changed files with 34 additions and 2 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -825,7 +825,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lines"
|
name = "lines"
|
||||||
version = "0.1.19"
|
version = "0.1.20"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "lines"
|
name = "lines"
|
||||||
version = "0.1.19"
|
version = "0.1.20"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors = ["janvete"]
|
authors = ["janvete"]
|
||||||
description = "TUI for running frequently used commands"
|
description = "TUI for running frequently used commands"
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ pub enum AppEvent {
|
||||||
Tick,
|
Tick,
|
||||||
Key(event::KeyEvent),
|
Key(event::KeyEvent),
|
||||||
Mouse(event::MouseEvent),
|
Mouse(event::MouseEvent),
|
||||||
|
Paste(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn poll_event(timeout: Duration) -> io::Result<Option<AppEvent>> {
|
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()? {
|
match event::read()? {
|
||||||
Event::Key(key) => Ok(Some(AppEvent::Key(key))),
|
Event::Key(key) => Ok(Some(AppEvent::Key(key))),
|
||||||
Event::Mouse(mouse) => Ok(Some(AppEvent::Mouse(mouse))),
|
Event::Mouse(mouse) => Ok(Some(AppEvent::Mouse(mouse))),
|
||||||
|
Event::Paste(text) => Ok(Some(AppEvent::Paste(text))),
|
||||||
_ => Ok(Some(AppEvent::Tick)),
|
_ => Ok(Some(AppEvent::Tick)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -50,6 +52,7 @@ pub fn handle_event(app: &mut App, event: AppEvent) -> bool {
|
||||||
}
|
}
|
||||||
_ => true,
|
_ => 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 {
|
fn handle_search_event(app: &mut App, key: event::KeyEvent) -> bool {
|
||||||
let Some(state) = app.search_state.as_mut() else {
|
let Some(state) = app.search_state.as_mut() else {
|
||||||
app.exit_search();
|
app.exit_search();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue