From ef3f696689dfa960333e43106bebe0ee89bd43dc Mon Sep 17 00:00:00 2001 From: vasilito Date: Tue, 7 Jul 2026 10:05:43 +0300 Subject: [PATCH] W49: Search field auto-suggest from history When opening a Find or Replace prompt, prefill the input with the most recent search pattern from the history. The user can still type freely to override or press Backspace to clear it. Only applies to Find / Replace prompts (not GotoLine, etc.). Updated the existing alt_slash test to account for the auto-suggested prefix (it now presses Backspace 5 times to clear 'hello' before typing 'world'). Tests: 1407 pass, zero warnings. --- .../recipes/tui/tlc/source/src/editor/handlers.rs | 15 +++++++++++++++ local/recipes/tui/tlc/source/src/editor/mod.rs | 10 +++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/local/recipes/tui/tlc/source/src/editor/handlers.rs b/local/recipes/tui/tlc/source/src/editor/handlers.rs index 93741628e9..087090224c 100644 --- a/local/recipes/tui/tlc/source/src/editor/handlers.rs +++ b/local/recipes/tui/tlc/source/src/editor/handlers.rs @@ -1157,7 +1157,22 @@ impl Editor { /// [`Mode::Prompt`] with the given kind. The caller's keymap is /// responsible for routing the trigger key to Normal mode first. fn open_prompt(&mut self, kind: PromptKind) -> EditorResult { + // Auto-suggest: prefill the search prompt with the most + // recent search pattern. The user can still type freely to + // override. Only applies to Find / Replace (not Goto, etc.). + let prefill: Option = match kind { + PromptKind::Find | PromptKind::Replace => self + .search + .history() + .last() + .cloned(), + _ => None, + }; self.prompt_input.clear(); + if let Some(text) = prefill { + self.prompt_input.text = text; + self.prompt_input.cursor = self.prompt_input.text.chars().count(); + } self.mode = Mode::Prompt(kind); EditorResult::Running } diff --git a/local/recipes/tui/tlc/source/src/editor/mod.rs b/local/recipes/tui/tlc/source/src/editor/mod.rs index e12f69ba8b..61ac391b77 100644 --- a/local/recipes/tui/tlc/source/src/editor/mod.rs +++ b/local/recipes/tui/tlc/source/src/editor/mod.rs @@ -2070,13 +2070,21 @@ mod tests { fn alt_slash_in_find_prompt_opens_history_popup() { let mut e = make_empty(); e.insert_str("hello world hello"); - // Run two searches to populate history. + // Run two searches to populate history. The second one + // has to clear the auto-suggested "hello" prefix before + // typing "world". e.handle_key(Key::alt('f')); for c in "hello".chars() { e.handle_key(Key::from_char(c)); } e.handle_key(Key::ENTER); e.handle_key(Key::alt('f')); + // Clear the auto-suggested "hello" from the prompt. + e.handle_key(Key::BACKSPACE); + e.handle_key(Key::BACKSPACE); + e.handle_key(Key::BACKSPACE); + e.handle_key(Key::BACKSPACE); + e.handle_key(Key::BACKSPACE); for c in "world".chars() { e.handle_key(Key::from_char(c)); }