From 3b30d92b6224eabe78115fd667efa8f35d5d6a4d Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 31 Aug 2022 07:33:46 +0200 Subject: [PATCH] Commit transient edit when closing pager When selecting items in the pager, only the latest of those items is kept in the edit history, as so-called transient edit. Each new transient edit evicts any old transient edit (via undo). If the pager is closed by a command that performs another transient edit (like history-token-search-backward) we thus inadvertently undo (= remove) the token inserted by the pager. Fix this by closing a transient edit session when closing the pager. Token search will start its own session. Fixes #9160 --- src/reader.cpp | 1 + tests/checks/tmux-complete.fish | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/reader.cpp b/src/reader.cpp index a6ecf848f..83e37635a 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2045,6 +2045,7 @@ void reader_data_t::accept_autosuggestion(bool full, bool single, move_word_styl void reader_data_t::clear_pager() { pager.clear(); history_pager_active = false; + command_line_has_transient_edit = false; } void reader_data_t::select_completion_in_direction(selection_motion_t dir, diff --git a/tests/checks/tmux-complete.fish b/tests/checks/tmux-complete.fish index d810b4527..0e3365968 100644 --- a/tests/checks/tmux-complete.fish +++ b/tests/checks/tmux-complete.fish @@ -68,3 +68,9 @@ isolated-tmux capture-pane -p | head -1 # The second one is the autosuggestion. Maybe we should turn them off for this test. # TODO there should be a prefix ("prompt 4> foo4") but we fail to draw that in this case. # CHECK: {{.*}} b-short-arg a-long-arg{{.*}} + +# Check that completion pager followed by token search search inserts two separate tokens. +isolated-tmux send-keys C-u echo Space old-arg Enter C-l foo2 Space Tab Tab M-. +tmux-sleep +isolated-tmux capture-pane -p +# CHECK: prompt 5> foo2 aabc old-arg