diff --git a/core/kptui/src/main.rs b/core/kptui/src/main.rs index 9168764..f0b1d29 100644 --- a/core/kptui/src/main.rs +++ b/core/kptui/src/main.rs @@ -1,7 +1,7 @@ use kordophoned_client as daemon; 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 ratatui::prelude::*; use ratatui::widgets::*; @@ -542,7 +542,7 @@ fn run_app( } 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 { @@ -591,10 +591,10 @@ fn run_app( app.refresh_messages_in_flight = true; } } 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( app: &mut AppState, request_tx: &mpsc::Sender, - code: KeyCode, + key: KeyEvent, max_scroll: u16, ) { + let code = key.code; + let modifiers = key.modifiers; + match code { KeyCode::PageUp => scroll_up(app, 10), KeyCode::PageDown => scroll_down(app, 10, max_scroll), @@ -643,6 +646,15 @@ fn handle_chat_keys( } 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 => { let text = app.input.trim().to_string(); 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) { if amount > 0 { app.pinned_to_bottom = false;