From 8ddb078db8af228e2f39d3dd98d0287e98e092ea Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 5 Feb 2025 22:04:48 +0100 Subject: [PATCH] reader: Only maintain cursor position in non-empty prefix search Otherwise this would always move the cursor to the beginning. Fixes #11133 (cherry picked from commit db244e0492db4f4e6c5b0865a1cd591ba9104ce7) --- src/reader.rs | 4 +++- tests/pexpects/bind.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/reader.rs b/src/reader.rs index 5ee8559eb..a2392e7f8 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1909,7 +1909,9 @@ fn update_command_line_from_history_search(&mut self) { 0..self.command_line.len(), new_text, ); - if self.history_search.by_prefix() { + if self.history_search.by_prefix() + && !self.history_search.search_string().is_empty() + { self.command_line .set_position(self.history_search.search_string().len()); } diff --git a/tests/pexpects/bind.py b/tests/pexpects/bind.py index 4d1514fc2..c8169c1e5 100644 --- a/tests/pexpects/bind.py +++ b/tests/pexpects/bind.py @@ -372,6 +372,14 @@ send('\x02\x02\x02') # ctrl-b, backward-char sendline('\x1bu') # alt+u, upcase word expect_prompt("fooBAR") +sendline('bind ctrl-z history-prefix-search-backward') +expect_prompt() +sendline("echo this continues") +expect_prompt() +send("\x1A") +sendline(" with this text") +expect_prompt("this continues with this text") + sendline(""" bind ctrl-g " commandline --insert 'echo foo ar'