A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
fix keys dying in the /settings menu search (#3309)
kte7e27c24c073
diff --git a/crates/pa-tui/src/agents_view/data_input.rs b/crates/pa-tui/src/agents_view/data_input.rsindex bc32f54860..956898a695 100644--- a/crates/pa-tui/src/agents_view/data_input.rs+++ b/crates/pa-tui/src/agents_view/data_input.rs@@ -702,6 +702,16 @@ impl AgentsViewMode {}return;}+ // TS `Editor.handleInput`'s `deleteWordBackward` (ctrl+w / alt+backspace).+ if self+ .keybindings+ .matches(key, "tui.editor.deleteWordBackward")+ {+ if truncate_trailing_word(&mut self.query) {+ self.query_changed(false);+ }+ return;+ }// The printable decode the editor uses (`decode_printable`):// the space arrives as the `space` key id (TS parseKey maps the// raw space there), and the shift+letter ids decode to their@@ -850,3 +860,20 @@ impl AgentsViewMode {self.open_selected();}}++/// Delete the query's trailing word run plus the whitespace before it+/// (TS `Editor.deleteWordBackwards` with the caret at the text's end —+/// this view's query is append-only, so the caret always sits there):+/// the search input's punctuation-aware walk, so a dotted query+/// ("error.rs") loses its trailing word run and keeps "error." — a+/// whitespace-only scan would take the whole dotted word. Returns+/// whether anything was deleted: a no-op edit re-arms nothing.+fn truncate_trailing_word(query: &mut String) -> bool {+ let chars: Vec<char> = query.chars().collect();+ let start = crate::search_input::word_walk_start(query);+ if start == chars.len() {+ return false;+ }+ *query = chars[..start].iter().collect();+ true+}diff --git a/crates/pa-tui/src/agents_view/tests/search_selection.rs b/crates/pa-tui/src/agents_view/tests/search_selection.rsindex f245e40d9c..86a19b39c4 100644--- a/crates/pa-tui/src/agents_view/tests/search_selection.rs+++ b/crates/pa-tui/src/agents_view/tests/search_selection.rs@@ -100,6 +100,44 @@ fn a_matching_selection_still_moves_to_the_top_hit() {assert_eq!(mode.selected, first_selectable(&mode));}+/// The editor's word-delete binding (TS `Editor.handleInput`'s+/// `deleteWordBackward`, ctrl+w) deletes the query's trailing word.+#[test]+fn ctrl_w_deletes_the_query_s_trailing_word() {+ let mut mode = fresh_mode(search_roster());+ type_query(&mut mode, "gateway worker");+ assert_eq!(mode.query, "gateway worker");+ mode.handle_key("ctrl+w");+ assert_eq!(mode.query, "gateway ");+ mode.handle_key("alt+backspace");+ assert_eq!(mode.query, "");+ // An empty query's word-delete is a no-op that re-arms nothing.+ mode.handle_key("ctrl+w");+ assert_eq!(mode.query, "");+ assert_eq!(+ mode.rows.len(),+ 6,+ "every row returns with the cleared query"+ );+}++/// The word walk is punctuation-aware like the shared editor's+/// `delete_word_backward` (TS `moveWordBackwards`): a dotted query+/// loses its trailing word run only — "error.rs" keeps "error." —+/// never the whole dotted word a whitespace-only scan would take.+#[test]+fn ctrl_w_loses_only_the_trailing_word_run_in_a_dotted_query() {+ let mut mode = fresh_mode(search_roster());+ type_query(&mut mode, "error.rs");+ assert_eq!(mode.query, "error.rs");+ mode.handle_key("ctrl+w");+ assert_eq!(mode.query, "error.");+ mode.handle_key("ctrl+w");+ assert_eq!(mode.query, "error");+ mode.handle_key("ctrl+w");+ assert_eq!(mode.query, "");+}+/// Clearing the query (backspace to empty, ctrl+u, or escape) returns/// the selection to the session it sat on before the search began.#[test]diff --git a/crates/pa-tui/src/config_selector.rs b/crates/pa-tui/src/config_selector.rsindex e4243741a3..c1b7d1da70 100644--- a/crates/pa-tui/src/config_selector.rs+++ b/crates/pa-tui/src/config_selector.rs@@ -13,6 +13,7 @@ use std::time::{Duration, Instant};use crate::keybindings::{format_key_text, KeybindingsManager};use crate::keys::key_event_to_id;+use crate::search_input::SearchInput;use crate::theme::{Theme, ThemeColor};use crate::{Line, Span};@@ -84,7 +85,7 @@ pub struct ConfigSelector {kind: SelectorKind,rows: Vec<SelectorRow>,filtered: Vec<usize>,- query: String,+ search: SearchInput,selected: usize,}@@ -105,7 +106,7 @@ impl ConfigSelector {kind,rows,filtered,- query: String::new(),+ search: SearchInput::new(),selected: 0,};selector.select_first_item();@@ -121,14 +122,21 @@ impl ConfigSelector {/// The current filter query.#[must_use]pub fn query(&self) -> &str {- &self.query+ self.search.value()}/// Replace the filter query in one step (the `/model <search>` prefill;/// typing the same characters one key at a time cannot express a- /// space, which the key loop treats as toggle).+ /// space, which the key loop treats as toggle). The caret lands at+ /// the prefill's end, so the next keystroke extends it.pub fn set_query(&mut self, query: &str) {- self.query = query.to_string();+ self.search.prefill(query);+ self.apply_filter();+ }++ /// A bracketed paste into the filter (TS the search `Input`'s paste).+ pub fn paste(&mut self, text: &str) {+ self.search.paste(text);self.apply_filter();}@@ -216,17 +224,12 @@ impl ConfigSelector {if key == "space" || kb.matches(key, "tui.select.confirm") {return self.toggle_selected();}- if key == "backspace" {- self.query.pop();+ // TS `ConfigSelectorComponent.handleInput`'s final arm: every+ // other key id goes whole to the search `Input`.+ let previous = self.search.value().to_string();+ self.search.handle_key(key, kb);+ if self.search.value() != previous {self.apply_filter();- return None;- }- // Every other key with a printable identity edits the filter.- if let [character] = key.chars().collect::<Vec<char>>()[..] {- if !character.is_control() {- self.query.push(character);- self.apply_filter();- }}None}@@ -308,12 +311,12 @@ impl ConfigSelector {/// Rebuild the filtered view: items matching the query, plus the group/// and subgroup rows that contain them (TS `filterItems`).fn apply_filter(&mut self) {- if self.query.trim().is_empty() {+ if self.search.value().trim().is_empty() {self.filtered = (0..self.rows.len()).collect();self.select_first_item();return;}- let query = self.query.to_lowercase();+ let query = self.search.value().to_lowercase();let item_matches = |row: &SelectorRow| match row {SelectorRow::Item {label,@@ -456,8 +459,8 @@ impl ConfigSelector {lines.extend(crate::menu_panel::search_field_lines(theme,width,- &self.query,- self.query.chars().count(),+ self.search.value(),+ self.search.cursor(),true,self.search_placeholder(),));@@ -615,7 +618,7 @@ fn run_selector_surface(let action = match crossterm::event::read()? {Event::Key(key) => handle_key_event(&mut selector, key, &kb),Event::Paste(text) => {- selector_query_insert(&mut selector, &text);+ selector.paste(&text);None}_ => None,@@ -655,13 +658,6 @@ fn handle_key_event(selector.handle_key(&id, kb)}-fn selector_query_insert(selector: &mut ConfigSelector, text: &str) {- for c in text.chars() {- let id = c.to_string();- selector.handle_key(&id, &KeybindingsManager::new());- }-}-#[cfg(test)]mod tests {use super::*;@@ -712,6 +708,59 @@ mod tests {assert_eq!(selector.checked("kernel"), Some(false));}+ /// TS `ConfigSelectorComponent.handleInput`'s final arm hands every+ /// non-intercepted key to the search `Input`, so the word and line+ /// kills (ctrl+w, ctrl+u) edit the filter.+ #[test]+ fn word_and_line_edits_reach_the_filter() {+ let mut selector = ConfigSelector::new(rows());+ for key in ["k", "e", "r", "n", "e", "l"] {+ selector.handle_key(key, &kb());+ }+ assert_eq!(selector.query(), "kernel");+ selector.handle_key("ctrl+w", &kb());+ assert_eq!(selector.query(), "", "ctrl+w deletes the typed word");+ for key in ["b", "r", "o", "w", "s", "e", "r"] {+ selector.handle_key(key, &kb());+ }+ assert_eq!(selector.query(), "browser");+ selector.handle_key("ctrl+u", &kb());+ assert_eq!(selector.query(), "", "ctrl+u clears the line");+ }++ /// The filter's full grammar: home+delete edits the head, undo takes+ /// an edit back (TS the search `Input`'s bindings on the whole key+ /// ids).+ #[test]+ fn cursor_and_undo_bindings_reach_the_filter() {+ let mut selector = ConfigSelector::new(rows());+ for key in ["a", "b", "c"] {+ selector.handle_key(key, &kb());+ }+ assert_eq!(selector.query(), "abc");+ selector.handle_key("home", &kb());+ selector.handle_key("delete", &kb());+ assert_eq!(selector.query(), "bc", "home+delete removes the head");+ selector.handle_key("ctrl+-", &kb());+ assert_eq!(selector.query(), "abc", "undo takes the delete back");+ }++ /// The no-match edge state recovers through the same grammar: a+ /// garbage query that empties the list backspaces away, and the rows+ /// return.+ #[test]+ fn the_no_match_state_recovers_through_backspace() {+ let mut selector = ConfigSelector::new(rows());+ for key in ["z", "z"] {+ selector.handle_key(key, &kb());+ }+ assert!(selector.filtered.is_empty(), "garbage matches no row");+ selector.handle_key("backspace", &kb());+ selector.handle_key("backspace", &kb());+ assert_eq!(selector.query(), "");+ assert_eq!(selector.filtered.len(), rows().len(), "every row returns");+ }+/// The frame renders through the shared menu grammar: the title, the/// bordered search field, the `›` marker row, and the hint status row/// (the hints ride the bottom row, not a header line).@@ -816,6 +865,26 @@ mod keybind_tests {);}+ /// A rebound `tui.editor.deleteCharBackward` moves with the table+ /// (TS the search `Input`'s binding): the remapped key edits the+ /// filter and the freed key no longer deletes.+ #[test]+ fn a_remapped_backspace_binding_edits_the_filter() {+ let mut selector = selector();+ let kb = manager(&[("tui.editor.deleteCharBackward", &["ctrl+h"])]);+ for key in ["a", "b"] {+ selector.handle_key(key, &kb);+ }+ selector.handle_key("ctrl+h", &kb);+ assert_eq!(selector.query(), "a", "the remapped binding deletes");+ selector.handle_key("backspace", &kb);+ assert_eq!(+ selector.query(),+ "a",+ "the freed backspace matches no binding and never edits"+ );+ }+/// With both bindings remapped away from ctrl+c the key is a plain/// no-op (a control character never edits the filter): nothing/// hard-codes it anymore.diff --git a/crates/pa-tui/src/effort_picker.rs b/crates/pa-tui/src/effort_picker.rsindex 79faf5d9fa..5273d7cc33 100644--- a/crates/pa-tui/src/effort_picker.rs+++ b/crates/pa-tui/src/effort_picker.rs@@ -107,6 +107,12 @@ impl EffortPicker {}}+ /// One bracketed paste into the search (the config selector's own+ /// paste path).+ pub fn paste(&mut self, text: &str) {+ self.selector.paste(text);+ }+/// The session's levels the picker was built over.#[must_use]pub fn levels(&self) -> &[String] {diff --git a/crates/pa-tui/src/menu_panel.rs b/crates/pa-tui/src/menu_panel.rsindex 905ba1e060..243ab5a32f 100644--- a/crates/pa-tui/src/menu_panel.rs+++ b/crates/pa-tui/src/menu_panel.rs@@ -389,9 +389,15 @@ pub(crate) fn search_field_plain_row(line}-/// One input render (TS `Input.render`): prompt, the visible slice with the-/// caret (a reversed cell) at the cursor, and trailing padding.-fn input_render(theme: &Theme, width: usize, value: &str, cursor: usize, focused: bool) -> Line {+/// One input render (TS `Input.render`): the visible slice of the value with+/// the caret (a reversed cell) at the cursor. Callers draw the prompt.+pub(crate) fn input_render(+ theme: &Theme,+ width: usize,+ value: &str,+ cursor: usize,+ focused: bool,+) -> Line {let _ = theme;let available_width = width.saturating_sub(FIELD_PROMPT.len());if available_width == 0 {diff --git a/crates/pa-tui/src/provider_auth.rs b/crates/pa-tui/src/provider_auth.rsindex 08b4eb86b8..aeb9b33487 100644--- a/crates/pa-tui/src/provider_auth.rs+++ b/crates/pa-tui/src/provider_auth.rs@@ -327,6 +327,21 @@ impl ProviderAuthSelector {.map(|index| self.providers[*index].clone())}+ /// One bracketed paste (TS routes the raw data to the open input):+ /// the API-key prompt takes it, the provider search filters with it.+ pub fn paste(&mut self, text: &str) {+ match &mut self.mode {+ Mode::Prompt { input, .. } => input.paste(text),+ Mode::List => {+ let previous = self.search.value().to_string();+ self.search.paste(text);+ if self.search.value() != previous {+ self.refilter();+ }+ }+ }+ }+/// One key id (TS `handleInput`).pub fn handle_key(&mut self, key: &str, kb: &KeybindingsManager) -> AuthSelectorAction {if key == "ctrl+c" {@@ -684,6 +699,34 @@ mod tests {assert_eq!(selector.search.value(), "l");}+ /// A paste in the list filters the providers (the search takes it).+ #[test]+ fn a_paste_filters_the_provider_list() {+ let mut selector =+ ProviderAuthSelector::new(AuthSelectorKind::Login, vec![openai(), anthropic()]);+ selector.paste("open");+ assert_eq!(selector.search.value(), "open");+ assert_eq!(selector.filtered.len(), 1);+ }++ /// A paste lands in the API-key prompt (the key reaches the auth+ /// field, not the hidden composer behind).+ #[test]+ fn a_paste_types_into_the_api_key_prompt() {+ let mut selector = ProviderAuthSelector::new(AuthSelectorKind::Login, vec![openai()]);+ assert_eq!(+ selector.handle_key("enter", &kb()),+ AuthSelectorAction::None+ );+ selector.paste("sk-secret");+ match selector.handle_key("enter", &kb()) {+ AuthSelectorAction::Login { api_key, .. } => {+ assert_eq!(api_key.as_deref(), Some("sk-secret"));+ }+ other => panic!("expected a login submit, got {other:?}"),+ }+ }+#[test]fn enter_on_an_api_key_row_opens_the_prompt() {let mut selector =diff --git a/crates/pa-tui/src/search_input.rs b/crates/pa-tui/src/search_input.rsindex edd539c155..3de5f2645d 100644--- a/crates/pa-tui/src/search_input.rs+++ b/crates/pa-tui/src/search_input.rs@@ -7,7 +7,7 @@ use crate::keybindings::KeybindingsManager;/// The single-line search input (TS `Input`): value, cursor, undo stack,/// and an Emacs-style kill ring. Dispatch happens through the shared/// keybinding manager; the model selector owns when keys reach it.-#[derive(Debug)]+#[derive(Debug, Clone)]pub(crate) struct SearchInput {value: String,/// Cursor position in characters.@@ -232,22 +232,35 @@ impl SearchInput {self.move_word_forward();return;}- // Regular character input: printable characters only, one char at a- // time (control sequences never reach the value).- if let [character] = key.chars().collect::<Vec<char>>()[..] {- if !character.is_control() {- self.push_type_undo(character);- self.insert_at_cursor(&character.to_string());- }+ // Regular character input (TS `Input.handleInput`'s printable arm):+ // TS reads the raw space byte; the port gets the `space` key id,+ // which `decode_printable` maps back.+ if let Some(character) =+ crate::editor::decode_printable(key).and_then(|text| text.chars().next())+ {+ self.push_type_undo(character);+ self.insert_at_cursor(&character.to_string());}}/// A whole-word paste (bracketed paste, newlines stripped like TS).+ /// Control bytes never reach the value — the editor's `handle_paste`+ /// filters them — so an ESC/OSC sequence riding a paste cannot be+ /// stored in the query and re-emitted to the terminal on the next+ /// render of the field.pub(crate) fn paste(&mut self, text: &str) {- self.last_action = LastAction::None;- self.push_undo();let mut clean = text.replace(['\r', '\n'], "");clean = clean.replace('\t', " ");+ clean = clean.chars().filter(|c| !c.is_control()).collect();+ // A payload that filters to nothing (control-only bytes, empty+ // bracketed paste) changes nothing: no undo step is pushed, so+ // the next undo still undoes the typing (the editor's+ // `handle_paste` rule).+ if clean.is_empty() {+ return;+ }+ self.last_action = LastAction::None;+ self.push_undo();self.insert_at_cursor(&clean);}@@ -320,31 +333,11 @@ impl SearchInput {/// grapheme that ends at the cursor and a mid-cluster cursor/// classifies the partial cluster the same way TS does.fn move_word_backward(&mut self) {- use unicode_segmentation::UnicodeSegmentation;if self.cursor == 0 {return;}let before: String = self.chars()[..self.cursor].iter().collect();- let mut graphemes: Vec<&str> = before.graphemes(true).collect();- while graphemes.last().is_some_and(|g| g.chars().any(is_ws)) {- let g = graphemes.pop().expect("last checked Some");- self.cursor -= g.chars().count();- }- let Some(last) = graphemes.last().copied() else {- return;- };- let punctuation_run = last.chars().any(is_punct);- while let Some(g) = graphemes.last().copied() {- if punctuation_run {- if !g.chars().any(is_punct) {- break;- }- } else if g.chars().any(is_ws) || g.chars().any(is_punct) {- break;- }- graphemes.pop();- self.cursor -= g.chars().count();- }+ self.cursor = word_walk_start(&before);}/// Word-boundary walk forward (TS `moveWordForwards`), grapheme by@@ -413,6 +406,37 @@ fn is_punct(c: char) -> bool {crate::width::is_punctuation_char(c)}+/// The word walk TS `moveWordBackwards` runs on a before-cursor slice:+/// the char index where the run in front of the trailing whitespace+/// starts, the last grapheme's class deciding whether the run is+/// punctuation or word characters. The slice is segmented standalone,+/// exactly like the TS original, so the run starts at the grapheme that+/// ends the slice; an all-whitespace slice walks to 0. Shared by the+/// search input's cursor walk and the plain-string word deletes that+/// hold the caret at the slice's end.+pub(crate) fn word_walk_start(text: &str) -> usize {+ use unicode_segmentation::UnicodeSegmentation;+ let mut graphemes: Vec<&str> = text.graphemes(true).collect();+ while graphemes.last().is_some_and(|g| g.chars().any(is_ws)) {+ graphemes.pop();+ }+ let Some(last) = graphemes.last().copied() else {+ return 0;+ };+ let punctuation_run = last.chars().any(is_punct);+ while let Some(g) = graphemes.last().copied() {+ if punctuation_run {+ if !g.chars().any(is_punct) {+ break;+ }+ } else if g.chars().any(is_ws) || g.chars().any(is_punct) {+ break;+ }+ graphemes.pop();+ }+ graphemes.iter().map(|g| g.chars().count()).sum()+}+#[cfg(test)]mod tests {use super::*;@@ -430,6 +454,52 @@ mod tests {input}+ /// The `space` key id types a space: TS `Input.handleInput`'s+ /// regular-character arm reads the RAW space byte (0x20, printable),+ /// while this port receives TS's `space` key id, so the same printable+ /// decode that maps it back feeds the value.+ #[test]+ fn the_space_key_id_types_a_space() {+ let mut input = typed("a");+ input.handle_key("space", &kb());+ input.handle_key("b", &kb());+ assert_eq!(input.value(), "a b");+ assert_eq!(input.cursor(), 3);+ // Backspace walks the typed characters back out, space included.+ input.handle_key("backspace", &kb());+ assert_eq!(input.value(), "a ");+ input.handle_key("backspace", &kb());+ assert_eq!(input.value(), "a");+ }++ /// A paste's control bytes never reach the value (the editor's+ /// `handle_paste` filters them): an ESC/OSC sequence riding a+ /// bracketed paste would otherwise be stored in the query and+ /// re-emitted to the terminal on the next render of the field.+ #[test]+ fn paste_rejects_control_bytes() {+ let mut input = typed("a");+ input.paste("\u{1b}]8;;https://evil.example\u{7}b\u{7f}");+ // The ESC/BEL/DEL bytes are dropped (the payload's printable+ // characters stay text, like the editor's paste filter): no+ // control byte survives into the value, so the field's render+ // can never re-emit a terminal control sequence.+ assert_eq!(input.value(), "a]8;;https://evil.exampleb");+ assert!(!input.value().chars().any(char::is_control));+ }++ /// A control-only paste filters to nothing and changes nothing: no+ /// empty undo step is pushed (the editor's `handle_paste` rule), so+ /// the next undo still undoes the typing.+ #[test]+ fn a_control_only_paste_leaves_the_undo_stack_alone() {+ let mut input = typed("ab");+ input.paste("\u{1b}\u{7}");+ assert_eq!(input.value(), "ab");+ input.handle_key("ctrl+-", &kb());+ assert_eq!(input.value(), "", "undo removes the typing, not a no-op");+ }+#[test]fn typing_moves_the_cursor_and_backspace_deletes() {let mut input = typed("abc");diff --git a/crates/pa-tui/src/session_ui/keys.rs b/crates/pa-tui/src/session_ui/keys.rsindex 3774aa23f7..d1a45d2948 100644--- a/crates/pa-tui/src/session_ui/keys.rs+++ b/crates/pa-tui/src/session_ui/keys.rs@@ -349,21 +349,11 @@ impl SessionUi {/// an open `/model` picker pastes into its search field; otherwise the/// editor takes it.pub(crate) fn handle_paste(&mut self, text: &str, view: &mut AgentView) {- if let Some(picker) = view.model_picker.as_mut() {- picker.paste(text);- self.dirty = true;- return;- }- if let Some(mcp_view) = view.mcp_view.as_mut() {- mcp_view.paste(text);- self.dirty = true;- return;- }- // The bash view owns the whole frame while open (like its key- // dispatch): a paste never lands in the hidden editor prompt,- // where a later Enter would submit it unedited. The read-only- // goal panel and info panel consume it the same way.- if view.bash_view.is_some() || view.goal_panel.is_some() || view.info_panel.is_some() {+ // The overlays own the whole frame while open (like their key+ // dispatch): the paste lands in the overlay's own input or is+ // consumed by the input-less ones, never in the hidden editor+ // prompt behind.+ if view.route_paste(text) {self.dirty = true;return;}diff --git a/crates/pa-tui/src/settings_menu/menu_tests.rs b/crates/pa-tui/src/settings_menu/menu_tests.rsindex 015f5d4775..2092fbb801 100644--- a/crates/pa-tui/src/settings_menu/menu_tests.rs+++ b/crates/pa-tui/src/settings_menu/menu_tests.rs@@ -393,6 +393,62 @@ fn arrows_no_op_on_submenu_rows() {assert!(text.iter().any(|row| row.contains("Thinking Level")));}+/// A caret-only key in the search field keeps the filtered selection+/// (the config selector's re-filter rule: the filter re-runs only when+/// the query changed), so the row Space would activate stays the one+/// under the cursor.+#[test]+fn a_caret_move_keeps_the_filtered_selection() {+ let mut menu = menu();+ // "mo" leaves two rows (steering-mode, follow-up-mode).+ for key in ["m", "o"] {+ menu.handle_key(key, &kb());+ }+ assert!(menu.tabs[menu.tab].filtered.len() >= 2);+ menu.handle_key("down", &kb());+ let selected = menu.tabs[menu.tab].selected;+ assert!(selected > 0);+ // A caret move edits nothing: the selection stays on the row.+ menu.handle_key("ctrl+left", &kb());+ assert_eq!(+ menu.tabs[menu.tab].selected, selected,+ "a caret-only key keeps the selection"+ );+}++/// A paste on the empty-menu state (no tabs) is a no-op, like the+/// navigation keys: nothing panics, nothing types.+#[test]+fn a_paste_on_an_empty_menu_edits_nothing() {+ let mut menu = SettingsMenu::new(Vec::new());+ menu.paste("anything");+ assert!(menu.tabs.is_empty());+}++/// A paste while a submenu owns the frame edits nothing: the parent+/// list's search stays untouched behind it.+#[test]+fn a_paste_while_a_submenu_is_open_edits_nothing() {+ let mut menu = menu();+ menu.handle_key("2", &kb());+ menu.handle_key("enter", &kb());+ assert!(menu.sub.is_some());+ menu.paste("thinking");+ assert_eq!(menu.tabs[menu.tab].search.value(), "");+}++/// A paste lands in the search field (TS routes the raw paste to the+/// `Input`): TS's sanitize strips the spaces (Space stays the row+/// activation), the filter re-runs on the changed query.+#[test]+fn a_paste_types_into_the_search_query_without_spaces() {+ let mut menu = menu();+ menu.paste("auto comp");+ assert_eq!(menu.tabs[menu.tab].search.value(), "autocomp");+ assert_eq!(menu.tabs[menu.tab].filtered.len(), 1);+ assert_eq!(menu.rows[menu.tabs[menu.tab].filtered[0]].id, "autocompact");+}+#[test]fn digits_type_into_an_active_query() {let mut menu = menu();@@ -546,3 +602,85 @@ fn opening_into_a_setting_keeps_the_top_bar_and_the_padding() {.iter().any(|row| row.starts_with(" Enter select · Esc back")));}++/// The search field takes the WHOLE key id (TS `Input.handleInput`, the+/// `SettingsList.handleInput` final arm): Backspace deletes the query.+/// After garbage filters the list to the no-match row, backspacing it+/// away returns the settings rows.+#[test]+fn backspace_edits_the_search_query() {+ let mut menu = menu();+ for key in ["z", "q", "x"] {+ menu.handle_key(key, &kb());+ }+ let filtered = render_text(&menu);+ assert!(+ filtered+ .iter()+ .any(|row| row.contains("No matching settings")),+ "the garbage query filters the list to the no-match row"+ );+ assert!(+ !filtered.iter().any(|row| row.contains("Auto-compact")),+ "no settings row matches the garbage query"+ );+ for _ in 0..3 {+ menu.handle_key("backspace", &kb());+ }+ let text = render_text(&menu);+ assert!(+ text.iter().any(|row| row.contains("Auto-compact")),+ "the settings rows return once the query is backspaced away"+ );+ assert!(+ !text.iter().any(|row| row.contains("No matching settings")),+ "the no-match row clears with the query"+ );+}++/// Backspace at the empty-query boundary stays inside the menu (TS+/// `Input.handleBackspace` clamps at the cursor): the action is None+/// and the rows keep rendering — the menu neither closes nor strands on+/// its no-match row. Like every key that reaches the search field, the+/// press runs the filter pass, which re-lands the tab's selection on its+/// first row (TS `applyFilter`'s reset, kept for parity).+#[test]+fn backspace_on_an_empty_query_keeps_the_menu_open() {+ let mut menu = menu();+ assert_eq!(+ menu.handle_key("backspace", &kb()),+ SettingsMenuAction::None,+ "backspace with an empty query is a no-op action"+ );+ let text = render_text(&menu);+ assert!(+ text.iter().any(|row| row.contains("Auto-compact")),+ "the rows keep rendering: {text:?}"+ );+ assert!(+ !text.iter().any(|row| row.contains("No matching settings")),+ "the empty query keeps every row matched"+ );+}++/// Space keeps its row-activation meaning after the search field takes+/// whole key ids (TS sanitizes a bare space out of the query): the key+/// cycles the selected row's value and types nothing into the field.+#[test]+fn space_activates_instead_of_typing_into_the_query() {+ let mut menu = menu();+ let field_before = render_text(&menu)[1].clone();+ assert_eq!(+ menu.handle_key("space", &kb()),+ SettingsMenuAction::Change {+ id: "autocompact",+ value: "false".to_string()+ },+ "Space cycles the selected row (the operator's key vocabulary)"+ );+ let field_after = render_text(&menu)[1].clone();+ assert_eq!(+ field_before, field_after,+ "the sanitized Space never types into the search field"+ );+}diff --git a/crates/pa-tui/src/settings_menu/mod.rs b/crates/pa-tui/src/settings_menu/mod.rsindex 8d92ff3706..fbda3fa100 100644--- a/crates/pa-tui/src/settings_menu/mod.rs+++ b/crates/pa-tui/src/settings_menu/mod.rs@@ -489,18 +489,46 @@ impl SettingsMenu {if kb.matches(key, "tui.select.cancel") || key == "ctrl+c" {return SettingsMenuAction::Cancel;}- // TS sanitizes the input (a bare space types nothing) and every- // printable key edits the active tab's search field.- if let [character] = key.chars().collect::<Vec<char>>()[..] {- if !character.is_control() {- let tab = self.active_mut();- tab.search.handle_key(key, kb);- self.apply_filter();- }+ // TS `SettingsList.handleInput`: Space stays the row activation+ // above; every other key id goes whole to the active tab's search+ // input.+ let tab = self.active_mut();+ let previous = tab.search.value().to_string();+ tab.search.handle_key(key, kb);+ // The filter re-runs only when the query changed (the config+ // selector's rule): a caret-only key keeps the selection.+ let changed = tab.search.value() != previous;+ if changed {+ self.apply_filter();}SettingsMenuAction::None}+ /// One bracketed paste into the active tab's search field (TS routes+ /// the raw paste data to the `Input`): the sanitize strips the spaces+ /// (Space stays the row activation), and the filter re-runs when the+ /// query changed.+ pub fn paste(&mut self, text: &str) {+ // The submenu owns the frame while open (its key dispatch takes+ // every key first): a paste never edits the hidden parent list.+ if self.sub.is_some() {+ return;+ }+ // An empty row set carries no tabs (the menu renders its empty+ // state): nothing to paste into.+ if self.tabs.is_empty() {+ return;+ }+ let sanitized = text.replace(' ', "");+ let tab = self.active_mut();+ let previous = tab.search.value().to_string();+ tab.search.paste(&sanitized);+ let changed = tab.search.value() != previous;+ if changed {+ self.apply_filter();+ }+ }+/// Enter/Space on the selection (TS `activateItem`): submenus open;/// value rows cycle to the next value.fn activate_selected(&mut self) -> SettingsMenuAction {diff --git a/crates/pa-tui/src/tree_list.rs b/crates/pa-tui/src/tree_list.rsindex de17a25026..e133f5e07e 100644--- a/crates/pa-tui/src/tree_list.rs+++ b/crates/pa-tui/src/tree_list.rs@@ -884,21 +884,30 @@ impl TreeList {}} else if kb.matches(id, "app.tree.toggleLabelTimestamp") {self.show_label_timestamps = !self.show_label_timestamps;- } else {- // Printable characters build the search query (TS: control- // characters never append).- let has_control = id- .chars()- .any(|c| c.is_control() || matches!(u32::from(c), 0x7f..=0x9f));- if !has_control && !id.is_empty() && !id.contains('+') {- self.search_query.push_str(id);- self.folded.clear();- self.apply_filter();- }+ } else if let Some(text) = crate::editor::decode_printable(id) {+ // Printable characters build the search query. TS's final arm+ // reads raw key data, where only printables join; the port gets+ // parsed ids, so the editor's printable decode gates the append.+ self.search_query.push_str(&text);+ self.folded.clear();+ self.apply_filter();}action}+ /// One bracketed paste into the search query: TS's raw-data arm+ /// drops the control bytes (its `hasControlChars` gate), the+ /// printable text joins the query, and the folds re-run.+ pub fn paste(&mut self, text: &str) {+ let clean: String = text.chars().filter(|c| !c.is_control()).collect();+ if clean.is_empty() {+ return;+ }+ self.search_query.push_str(&clean);+ self.folded.clear();+ self.apply_filter();+ }+/// Update one node's label after a save (TS `updateNodeLabel`).pub fn update_node_label(&mut self, entry_id: &str, label: Option<String>, timestamp: &str) {if let Some(node) = selfdiff --git a/crates/pa-tui/src/tree_list/tests.rs b/crates/pa-tui/src/tree_list/tests.rsindex 6cc04c34d3..903fbea92b 100644--- a/crates/pa-tui/src/tree_list/tests.rs+++ b/crates/pa-tui/src/tree_list/tests.rs@@ -217,6 +217,86 @@ fn search_filters_and_backspace_restores() {assert_eq!(tree.search_query(), "secon");}+/// One bracketed paste joins the search query: TS's raw-data gate drops+/// the control bytes, the printable text joins, and the filter re-runs.+#[test]+fn a_paste_joins_the_search_query() {+ let flat = vec![+ message_node("u1", None, "2024-01-01T00:00:01.000Z", "fix the parser"),+ assistant_text_node(+ "a1",+ Some("u1"),+ "2024-01-01T00:00:02.000Z",+ "parser answer",+ ),+ message_node("u2", Some("a1"), "2024-01-01T00:00:03.000Z", "second"),+ ];+ let mut tree = list(flat, Some("u2"));+ tree.paste("parser");+ assert_eq!(tree.search_query(), "parser");+ let visible: Vec<&str> = tree+ .filtered+ .iter()+ .map(|index| tree.flat[*index].data.entry.id().unwrap())+ .collect();+ assert_eq!(visible, vec!["u1", "a1"]);+ // The control bytes drop; the printable text around them joins.+ tree.paste("\u{1b}]8;;x\u{7}r");+ assert_eq!(tree.search_query(), "parser]8;;xr");+ // A control-only paste joins nothing.+ tree.paste("\u{1b}\u{7}");+ assert_eq!(tree.search_query(), "parser]8;;xr");+}++/// TS's final arm reads the RAW key data: only printable characters+/// join the query, and every special key arrives as an escape sequence (a+/// control character) and drops. This port receives parsed ids, so the+/// same decode gates the append: the bare multi-character ids ("space",+/// "delete", "home") must never join the query as their own names.+#[test]+fn named_key_ids_never_join_the_search_query() {+ let flat = vec![+ message_node("u1", None, "2024-01-01T00:00:01.000Z", "first"),+ assistant_text_node("a1", Some("u1"), "2024-01-01T00:00:02.000Z", "second"),+ message_node("u2", Some("a1"), "2024-01-01T00:00:03.000Z", "third"),+ ];+ let kb = KeybindingsManager::new();+ let mut tree = list(flat, Some("u2"));+ for key in ["s", "e"] {+ tree.handle_key(&kb, key);+ }+ assert_eq!(tree.search_query(), "se");+ // The named keys join nothing: delete/home drop, exactly as TS's+ // control-character check drops their escape sequences.+ tree.handle_key(&kb, "delete");+ tree.handle_key(&kb, "home");+ assert_eq!(tree.search_query(), "se");+}++/// The space key id types a space (TS appends the raw 0x20; the port+/// receives the `space` id).+#[test]+fn the_space_key_id_types_a_space() {+ let flat = vec![+ message_node("u1", None, "2024-01-01T00:00:01.000Z", "first"),+ assistant_text_node("a1", Some("u1"), "2024-01-01T00:00:02.000Z", "second"),+ message_node("u2", Some("a1"), "2024-01-01T00:00:03.000Z", "third"),+ ];+ let kb = KeybindingsManager::new();+ let mut tree = list(flat, Some("u2"));+ for key in ["s", "e", "space", "c", "o", "n", "d"] {+ tree.handle_key(&kb, key);+ }+ assert_eq!(tree.search_query(), "se cond");+ // The query with the space still matches the text with the space.+ let visible: Vec<&str> = tree+ .filtered+ .iter()+ .map(|index| tree.flat[*index].data.entry.id().unwrap())+ .collect();+ assert_eq!(visible, vec!["a1"], "the space is part of the match");+}+#[test]fn user_only_filter_keeps_hidden_intermediates_out_of_the_visible_tree() {let theme = crate::theme::Theme::builtin("prime", crate::theme::ColorMode::TrueColor);diff --git a/crates/pa-tui/src/tree_selector.rs b/crates/pa-tui/src/tree_selector.rsindex 964c82fa4a..83e309900a 100644--- a/crates/pa-tui/src/tree_selector.rs+++ b/crates/pa-tui/src/tree_selector.rs@@ -3,6 +3,7 @@//! (TS `TreeSelectorComponent` + interactive-mode's navigate flow).use crate::keybindings::KeybindingsManager;+use crate::search_input::SearchInput;use crate::theme::{Theme, ThemeColor};use crate::tree_list::{FilterMode, TreeList, TreeListAction};use crate::tree_nodes::{build_tree, TreeNode};@@ -35,12 +36,20 @@ pub enum TreeSelectorAction {enum Mode {/// The tree list.Tree,- /// The label input for one entry (TS `LabelInput`).- LabelInput { entry_id: String, input: String },+ /// The label input for one entry (TS `LabelInput`): the search+ /// input holds the draft, so its full edit grammar (Backspace,+ /// Delete, the word/line kills) owns the non-intercepted keys.+ LabelInput {+ entry_id: String,+ input: SearchInput,+ },/// "Summarize branch?" (the TS three-option selector).Summarize { target_id: String, selected: usize },/// Custom summarization instructions (the TS inline editor).- CustomPrompt { target_id: String, input: String },+ CustomPrompt {+ target_id: String,+ input: SearchInput,+ },}/// The summarize options, in order.@@ -105,6 +114,17 @@ impl TreeSelector {.update_node_label(entry_id, label.map(str::to_string), "");}+ /// One bracketed paste (TS routes the raw data to the open input):+ /// the label and custom-prompt inputs take it, the tree search+ /// appends it, and the summarize choice list consumes it.+ pub fn paste(&mut self, text: &str) {+ match &mut self.mode {+ Mode::Tree => self.list.paste(text),+ Mode::LabelInput { input, .. } | Mode::CustomPrompt { input, .. } => input.paste(text),+ Mode::Summarize { .. } => {}+ }+ }+/// Handle one key id; the emitted action carries the caller's work.pub fn handle_key(&mut self, kb: &KeybindingsManager, id: &str) -> TreeSelectorAction {match &mut self.mode {@@ -127,18 +147,20 @@ impl TreeSelector {}TreeListAction::Cancel => TreeSelectorAction::Cancel,TreeListAction::EditLabel(entry_id) => {+ // TS `LabelInput` seeds the input with the current label+ // (`setValue`, which leaves the caret at 0); the port's+ // prefill puts it at the end.let current = self.list.label_of(&entry_id).unwrap_or_default();- self.mode = Mode::LabelInput {- entry_id,- input: current,- };+ let mut input = SearchInput::new();+ input.prefill(¤t);+ self.mode = Mode::LabelInput { entry_id, input };TreeSelectorAction::None}TreeListAction::None => TreeSelectorAction::None,},Mode::LabelInput { entry_id, input } => {if kb.matches(id, "tui.select.confirm") {- let label = input.trim().to_string();+ let label = input.value().trim().to_string();let label = (!label.is_empty()).then_some(label);let action = TreeSelectorAction::LabelChange {entry_id: entry_id.clone(),@@ -149,13 +171,9 @@ impl TreeSelector {} else if kb.matches(id, "tui.select.cancel") {self.mode = Mode::Tree;TreeSelectorAction::None- } else if kb.matches(id, "tui.editor.deleteCharBackward") {- input.pop();- TreeSelectorAction::None- } else if let Some(ch) = printable(id) {- input.push(ch);- TreeSelectorAction::None} else {+ // TS `LabelInput.handleInput`: every other key id goes whole to the input.+ input.handle_key(id, kb);TreeSelectorAction::None}}@@ -187,7 +205,7 @@ impl TreeSelector {let target_id = target_id.clone();self.mode = Mode::CustomPrompt {target_id,- input: String::new(),+ input: SearchInput::new(),};TreeSelectorAction::None}@@ -208,7 +226,7 @@ impl TreeSelector {}Mode::CustomPrompt { target_id, input } => {if kb.matches(id, "tui.select.confirm") {- let instructions = input.trim().to_string();+ let instructions = input.value().trim().to_string();let target_id = target_id.clone();self.mode = Mode::Tree;TreeSelectorAction::Navigate {@@ -224,13 +242,10 @@ impl TreeSelector {selected: 2,};TreeSelectorAction::None- } else if kb.matches(id, "tui.editor.deleteCharBackward") {- input.pop();- TreeSelectorAction::None- } else if let Some(ch) = printable(id) {- input.push(ch);- TreeSelectorAction::None} else {+ // TS's custom-prompt editor (`ExtensionEditorComponent`) takes+ // every other key id whole.+ input.handle_key(id, kb);TreeSelectorAction::None}}@@ -338,12 +353,7 @@ impl TreeSelector {width,"",));- let row = if input.is_empty() {- vec![crate::Span::raw(" ")]- } else {- vec![crate::Span::raw(format!(" {input}"))]- };- lines.push(truncate_line(&row, width, ""));+ lines.push(input_row(theme, width, input));lines.push(truncate_line(&vec![theme.fg_span(ThemeColor::Muted, input_pane_hint(kb, "save", "cancel"))],@@ -362,12 +372,7 @@ impl TreeSelector {width,"",));- let row = if input.is_empty() {- vec![crate::Span::raw(" ")]- } else {- vec![crate::Span::raw(format!(" {input}"))]- };- lines.push(truncate_line(&row, width, ""));+ lines.push(input_row(theme, width, input));lines.push(truncate_line(&vec![theme.fg_span(ThemeColor::Muted, input_pane_hint(kb, "save", "cancel"))],width,@@ -401,6 +406,20 @@ fn input_pane_hint(kb: &KeybindingsManager, confirm_action: &str, cancel_action:format!(" {segments}")}+/// The input panes' field row (TS `LabelInput.render`): the two-space+/// indent, then `Input.render` at the remaining width with its caret.+fn input_row(theme: &Theme, width: usize, input: &SearchInput) -> Line {+ let mut row = vec![crate::Span::raw(" ")];+ row.extend(crate::menu_panel::input_render(+ theme,+ width.saturating_sub(2),+ input.value(),+ input.cursor(),+ /*focused*/ true,+ ));+ truncate_line(&row, width, "")+}+/// Render the summarize choice list (the three TS options; row one is/// "No summary").fn render_choice(@@ -433,13 +452,6 @@ fn render_choice(lines}-/// One key id's printable character, when it is one (search/input typing).-fn printable(id: &str) -> Option<char> {- let mut chars = id.chars();- let c = chars.next()?;- (chars.next().is_none() && !c.is_control()).then_some(c)-}-#[cfg(test)]mod tests {use super::*;@@ -582,6 +594,169 @@ mod tests {assert!(!text.contains("Esc back"), "{text}");}+ /// Every non-intercepted key reaches the label input: the typed+ /// space lands, ctrl+w deletes the trailing word, ctrl+u clears the+ /// draft.+ #[test]+ fn label_input_edits_through_the_full_key_grammar() {+ let theme = Theme::builtin("prime", ColorMode::TrueColor);+ let kb = KeybindingsManager::new();+ let mut sel = selector();+ sel.handle_key(&kb, "shift+l");+ for key in ["a", "b", "space", "c", "d"] {+ sel.handle_key(&kb, key);+ }+ let text = frame_text(&sel.render(&theme, 120, &kb));+ assert!(text.contains("ab cd"), "the typed space lands: {text}");+ sel.handle_key(&kb, "ctrl+w");+ let text = frame_text(&sel.render(&theme, 120, &kb));+ assert!(+ text.contains("ab "),+ "ctrl+w deletes the trailing word: {text}"+ );+ // The cleared draft saves as the label's removal (TS+ // `onSubmit`'s empty-label arm — the frame's hint rows would+ // swallow a plain substring check, so the action carries the+ // proof).+ sel.handle_key(&kb, "ctrl+u");+ let action = sel.handle_key(&kb, "enter");+ assert_eq!(+ action,+ TreeSelectorAction::LabelChange {+ entry_id: "n0".to_string(),+ label: None,+ },+ "ctrl+u clears the label"+ );+ // The save hands a typed draft out (TS `onSubmit`).+ sel.handle_key(&kb, "shift+l");+ sel.handle_key(&kb, "x");+ let action = sel.handle_key(&kb, "enter");+ assert_eq!(+ action,+ TreeSelectorAction::LabelChange {+ entry_id: "n0".to_string(),+ label: Some("x".to_string()),+ }+ );+ }++ /// TS's custom-prompt editor (the `ExtensionEditorComponent`) hands+ /// every non-intercepted key to the full editor grammar.+ #[test]+ fn custom_prompt_edits_through_the_full_key_grammar() {+ let theme = Theme::builtin("prime", ColorMode::TrueColor);+ let kb = KeybindingsManager::new();+ let mut sel = selector();+ // Enter opens the summarize choice; its third option opens the+ // custom-prompt editor.+ sel.handle_key(&kb, "enter");+ sel.handle_key(&kb, "down");+ sel.handle_key(&kb, "down");+ sel.handle_key(&kb, "enter");+ for key in ["s", "u", "m", "space", "i", "t"] {+ sel.handle_key(&kb, key);+ }+ let text = frame_text(&sel.render(&theme, 120, &kb));+ assert!(text.contains("sum it"), "the typed space lands: {text}");+ sel.handle_key(&kb, "ctrl+w");+ let text = frame_text(&sel.render(&theme, 120, &kb));+ assert!(+ text.contains("sum "),+ "ctrl+w deletes the trailing word: {text}"+ );+ // Enter submits the trimmed instructions (TS `onSubmit`).+ let action = sel.handle_key(&kb, "enter");+ assert_eq!(+ action,+ TreeSelectorAction::Navigate {+ target_id: "n0".to_string(),+ summarize: true,+ custom_instructions: Some("sum".to_string()),+ }+ );+ // The cancel arm keeps its ladder: escape returns to the choice,+ // and Enter on the choice re-opens the editor with an empty draft+ // (TS's cancelled editor loops back to the choice — the frame's+ // hint rows would swallow a plain substring check, so the+ // submitted instructions carry the proof).+ let mut sel = selector();+ sel.handle_key(&kb, "enter");+ sel.handle_key(&kb, "down");+ sel.handle_key(&kb, "down");+ sel.handle_key(&kb, "enter");+ for key in ["o", "l", "d"] {+ sel.handle_key(&kb, key);+ }+ sel.handle_key(&kb, "escape");+ sel.handle_key(&kb, "enter");+ sel.handle_key(&kb, "b");+ let action = sel.handle_key(&kb, "enter");+ assert_eq!(+ action,+ TreeSelectorAction::Navigate {+ target_id: "n0".to_string(),+ summarize: true,+ custom_instructions: Some("b".to_string()),+ },+ "the reopened editor starts empty, so the draft is exactly the new keystroke"+ );+ }++ /// A paste lands in the active input (TS routes the raw data to the+ /// open `Input`): the label editor takes it, the tree search appends+ /// it, and the summarize choice list consumes it.+ #[test]+ fn a_paste_reaches_the_open_input() {+ let kb = KeybindingsManager::new();+ // The label input.+ let mut sel = selector();+ sel.handle_key(&kb, "shift+l");+ sel.paste("renamed");+ let value = match &sel.mode {+ Mode::LabelInput { input, .. } => input.value().to_string(),+ _ => panic!("the label input stays open"),+ };+ assert_eq!(value, "renamed");+ sel.handle_key(&kb, "escape");+ // The tree search appends it.+ sel.paste("chain");+ assert_eq!(sel.list.search_query(), "chain");+ // The summarize choice list consumes it (a fresh selector, the+ // search-filtered list above has no confirm target).+ let mut sel = selector();+ sel.handle_key(&kb, "enter");+ assert!(matches!(sel.mode, Mode::Summarize { .. }));+ sel.paste("ignored");+ assert_eq!(sel.list.search_query(), "");+ }++ /// The label pane draws its caret at the cursor (TS `Input.render`'s+ /// reversed cell): two lefts after "abc" put it on the "b".+ #[test]+ fn label_input_draws_the_caret_at_the_cursor() {+ let theme = Theme::builtin("prime", ColorMode::TrueColor);+ let kb = KeybindingsManager::new();+ let mut sel = selector();+ sel.handle_key(&kb, "shift+l");+ for key in ["a", "b", "c", "left", "left"] {+ sel.handle_key(&kb, key);+ }+ let frame = sel.render(&theme, 120, &kb);+ let is_caret = |span: &crate::Span| {+ span.style+ .add_modifier+ .contains(ratatui::style::Modifier::REVERSED)+ };+ let row = frame+ .iter()+ .find(|line| line.iter().any(is_caret))+ .expect("the label row draws a caret");+ let at = row.iter().position(is_caret).expect("the caret cell");+ let before: String = row[..at].iter().map(|span| span.content.as_str()).collect();+ assert_eq!((before.as_str(), row[at].content.as_str()), (" a", "b"));+ }+/// The `get_session_tree` wire payload of a linear chain of user/// messages `n0..n{depth-1}`, leaf at the far end.fn wire_chain(depth: usize) -> Value {diff --git a/crates/pa-tui/src/view.rs b/crates/pa-tui/src/view.rsindex 6d80ae4c28..5b8788653b 100644--- a/crates/pa-tui/src/view.rs+++ b/crates/pa-tui/src/view.rs@@ -327,6 +327,55 @@ impl AgentView {)}+ /// One paste routed by the open overlay, the key dispatch's order:+ /// the overlay's own input takes it, the input-less overlays consume+ /// it, and the bare dock's editor takes it when nothing is open.+ /// Returns whether an overlay took or consumed the paste.+ pub fn route_paste(&mut self, text: &str) -> bool {+ if let Some(picker) = self.model_picker.as_mut() {+ picker.paste(text);+ return true;+ }+ if let Some(picker) = self.effort_picker.as_mut() {+ picker.paste(text);+ return true;+ }+ if let Some(mcp) = self.mcp_view.as_mut() {+ mcp.paste(text);+ return true;+ }+ if let Some(selector) = self.tree_selector.as_mut() {+ selector.paste(text);+ return true;+ }+ if let Some(auth) = self.provider_auth.as_mut() {+ auth.paste(text);+ return true;+ }+ if let Some(menu) = self.settings_menu.as_mut() {+ menu.paste(text);+ return true;+ }+ // The input-less frame owners (the key dispatch's same set): the+ // heartbeats picker, the bash view, the read-only goal and info+ // panels, the fork selector, the pending confirm, the share+ // loader, the reload box, and the auth panel (its own channel+ // drives it). None of them leaves a paste to the editor behind.+ if self.heartbeats_picker.is_some()+ || self.bash_view.is_some()+ || self.goal_panel.is_some()+ || self.info_panel.is_some()+ || self.fork_selector.is_some()+ || self.confirm.is_some()+ || self.share_loader.is_some()+ || self.reload_box.is_some()+ || self.auth_panel.is_some()+ {+ return true;+ }+ false+ }+#[must_use]pub fn new(theme: Theme) -> Self {Self {diff --git a/crates/pa-tui/src/view/tests.rs b/crates/pa-tui/src/view/tests.rsindex 73704e156d..b33e3465d8 100644--- a/crates/pa-tui/src/view/tests.rs+++ b/crates/pa-tui/src/view/tests.rs@@ -12,6 +12,47 @@ fn view() -> AgentView {AgentView::new(Theme::builtin("prime", ColorMode::TrueColor))}+/// A paste never reaches the editor behind an overlay (the key+/// dispatch's frame owners): the input-bearing pickers take it, the+/// input-less overlays consume it, and only the bare dock's editor+/// sees it.+#[test]+fn a_paste_never_reaches_the_editor_behind_an_overlay() {+ let editor_text = |view: &AgentView| view.editor.get_lines().join("\n");+ // The /effort picker takes it into its search.+ let mut v = view();+ v.effort_picker = Some(crate::effort_picker::EffortPicker::new(+ &["high".to_string()],+ None,+ ));+ assert!(v.route_paste("effort"));+ assert_eq!(editor_text(&v), "");+ // The /login provider selector takes it into its search.+ let mut v = view();+ v.provider_auth = Some(crate::provider_auth::ProviderAuthSelector::new(+ crate::provider_auth::AuthSelectorKind::Login,+ Vec::new(),+ ));+ assert!(v.route_paste("login"));+ assert_eq!(editor_text(&v), "");+ // The settings menu takes it into its search.+ let mut v = view();+ v.settings_menu = Some(crate::settings_menu::SettingsMenu::new(Vec::new()));+ assert!(v.route_paste("setting"));+ assert_eq!(editor_text(&v), "");+ // The input-less overlays consume it (the reload box stands in for+ // the whole consume set).+ let mut v = view();+ v.reload_box = Some("reloading".to_string());+ assert!(v.route_paste("never"));+ assert_eq!(editor_text(&v), "");+ // The bare dock: the editor takes it.+ let mut v = view();+ assert!(!v.route_paste("direct"));+ v.editor.handle_paste("direct");+ assert_eq!(editor_text(&v), "direct");+}+fn text_of(line: &Line) -> String {line.iter().map(|s| s.content.as_str()).collect::<String>()}diff --git a/crates/pa-tui/tests/settings_menu_headless.rs b/crates/pa-tui/tests/settings_menu_headless.rsindex 31172d130b..52fce61cda 100644--- a/crates/pa-tui/tests/settings_menu_headless.rs+++ b/crates/pa-tui/tests/settings_menu_headless.rs@@ -5,8 +5,9 @@//! (the arrows' old tab job is rebinded away), the detail block's//! separator rule, the description-matched hint padding, the two//! open-into-a-setting regression pins (the top bar and the padding-x-//! stay), and the fullscreen setting's retirement (the always-fullscreen-//! surface has no toggle left to advertise).+//! stay), the search field's edit keys after a no-match query, and the+//! fullscreen setting's retirement (the always-fullscreen surface has no+//! toggle left to advertise).#![cfg(unix)]// Pedantic-gate exceptions (every other pedantic warning in this crate is// fixed in place; each exception carries its one-line justification):@@ -729,3 +730,37 @@ fn the_fullscreen_setting_and_command_are_retired() {"the retired command's description is gone: {all}");}++/// The search field keeps its edit keys after a no-match query: the+/// garbage backspaces away, the rows return, and Space still cycles+/// the selected row (TS `SettingsList.handleInput`).+#[test]+fn a_no_match_query_backspaces_away_and_space_still_cycles() {+ let mut steps = open_settings();+ for c in ['z', 'q', 'x'] {+ steps.push(HeadlessStep::Key(key(KeyCode::Char(c))));+ }+ steps.push(HeadlessStep::WaitRender {+ needle: "No matching settings".to_string(),+ timeout_ms: 5000,+ });+ for _ in 0..3 {+ steps.push(HeadlessStep::Key(key(KeyCode::Backspace)));+ }+ steps.push(HeadlessStep::WaitRender {+ needle: "Auto-compact".to_string(),+ timeout_ms: 5000,+ });+ steps.push(HeadlessStep::Key(key(KeyCode::Char(' '))));+ steps.push(HeadlessStep::WaitMs(300));+ let (frames, _) = run_plan(steps);+ let rows = frame_rows(frames.last().expect("the run captured frames"));+ let row = rows+ .iter()+ .find(|row| row.contains("Auto-compact"))+ .expect("the settings rows return once the query is backspaced away");+ assert!(+ row.contains("false"),+ "Space still cycles the selected row: {row}"+ );+}