From 8b9f7dbf45ab3a2b4f08f192dfc0bf7573b5f80d Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 30 Jan 2022 19:19:43 +0100 Subject: [PATCH] Commit transient edit when history search ends A history search ends when you move the cursor, but the commandline inserted by history search is still marked as transient. This means that the next history search will clear the transient commandline. This means we are dropping an undo point, for example: echo 11 echo 1 echo autosuggestion echo^P # commandline is "echo 1" ^A # stop history search ^P # commandline is "echo 11" ^Z # Bug: commandline goes back to "echo", but it should be "echo 1" In the worst case, we are switching from line-search to token-search (see the attached test case). Clearing the transient edit means the line is gone and only the token is left on the command line. --- src/reader.cpp | 1 + tests/checks/tmux-history-search.fish | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/checks/tmux-history-search.fish diff --git a/src/reader.cpp b/src/reader.cpp index 98f892645..eb612815f 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -4094,6 +4094,7 @@ maybe_t reader_data_t::readline(int nchars_or_0) { clear_transient_edit(); } history_search.reset(); + command_line_has_transient_edit = false; } rls.last_cmd = readline_cmd; diff --git a/tests/checks/tmux-history-search.fish b/tests/checks/tmux-history-search.fish new file mode 100644 index 000000000..877651cbf --- /dev/null +++ b/tests/checks/tmux-history-search.fish @@ -0,0 +1,14 @@ +#RUN: %fish %s +#REQUIRES: command -v tmux + +isolated-tmux-start + +isolated-tmux send-keys 'true needle' Enter +# CHECK: prompt 0> true needle +tmux-sleep +isolated-tmux send-keys 'true hay ee hay' Enter +# CHECK: prompt 1> true hay ee hay +isolated-tmux send-keys C-p C-a M-f M-f M-f M-. +# CHECK: prompt 2> true hay needle hay +tmux-sleep +isolated-tmux capture-pane -p