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)); }