Private
Public Access
1
0

kptui: handle some emacs like keyboard shortcuts

This commit is contained in:
2026-02-11 14:48:00 -08:00
parent 9a3c808095
commit 1febd91c2c

View File

@@ -1,7 +1,7 @@
use kordophoned_client as daemon; use kordophoned_client as daemon;
use anyhow::Result; use anyhow::Result;
use crossterm::event::{Event as CEvent, KeyCode, KeyEventKind, KeyModifiers}; use crossterm::event::{Event as CEvent, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
use ratatui::prelude::*; use ratatui::prelude::*;
use ratatui::widgets::*; use ratatui::widgets::*;
@@ -542,7 +542,7 @@ fn run_app(
} }
KeyCode::Char('i') if app.focus != Focus::Input => app.focus = Focus::Input, KeyCode::Char('i') if app.focus != Focus::Input => app.focus = Focus::Input,
_ => { _ => {
handle_chat_keys(&mut app, &request_tx, key.code, max_scroll); handle_chat_keys(&mut app, &request_tx, key, max_scroll);
} }
}, },
ViewMode::Split => match key.code { ViewMode::Split => match key.code {
@@ -591,10 +591,10 @@ fn run_app(
app.refresh_messages_in_flight = true; app.refresh_messages_in_flight = true;
} }
} else { } else {
handle_chat_keys(&mut app, &request_tx, key.code, max_scroll); handle_chat_keys(&mut app, &request_tx, key, max_scroll);
} }
} }
_ => handle_chat_keys(&mut app, &request_tx, key.code, max_scroll), _ => handle_chat_keys(&mut app, &request_tx, key, max_scroll),
}, },
} }
} }
@@ -629,9 +629,12 @@ fn run_app(
fn handle_chat_keys( fn handle_chat_keys(
app: &mut AppState, app: &mut AppState,
request_tx: &mpsc::Sender<daemon::Request>, request_tx: &mpsc::Sender<daemon::Request>,
code: KeyCode, key: KeyEvent,
max_scroll: u16, max_scroll: u16,
) { ) {
let code = key.code;
let modifiers = key.modifiers;
match code { match code {
KeyCode::PageUp => scroll_up(app, 10), KeyCode::PageUp => scroll_up(app, 10),
KeyCode::PageDown => scroll_down(app, 10, max_scroll), KeyCode::PageDown => scroll_down(app, 10, max_scroll),
@@ -643,6 +646,15 @@ fn handle_chat_keys(
} }
match code { match code {
KeyCode::Char('u') if modifiers.contains(KeyModifiers::CONTROL) => {
app.input.clear();
}
KeyCode::Backspace if modifiers.contains(KeyModifiers::ALT) => {
delete_prev_word(&mut app.input);
}
KeyCode::Char('w') if modifiers.contains(KeyModifiers::CONTROL) => {
delete_prev_word(&mut app.input);
}
KeyCode::Enter => { KeyCode::Enter => {
let text = app.input.trim().to_string(); let text = app.input.trim().to_string();
if text.is_empty() { if text.is_empty() {
@@ -673,6 +685,15 @@ fn handle_chat_keys(
} }
} }
fn delete_prev_word(input: &mut String) {
while input.chars().last().is_some_and(|c| c.is_whitespace()) {
input.pop();
}
while input.chars().last().is_some_and(|c| !c.is_whitespace()) {
input.pop();
}
}
fn scroll_up(app: &mut AppState, amount: u16) { fn scroll_up(app: &mut AppState, amount: u16) {
if amount > 0 { if amount > 0 {
app.pinned_to_bottom = false; app.pinned_to_bottom = false;