From 459ac2b5664613ba23459f23d79f4250714228c4 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 24 Feb 2021 21:00:56 +0100 Subject: [PATCH] Reset the readline loop state when setting the buffer Fixes #7740. --- src/reader.cpp | 9 +++++++++ tests/pexpects/complete.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/reader.cpp b/src/reader.cpp index 3a0fd0505..e64f4c550 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -580,6 +580,9 @@ class reader_data_t : public std::enable_shared_from_this { /// When backspacing, we temporarily suppress autosuggestions. bool suppress_autosuggestion{false}; + /// HACK: A flag to reset the loop state from the outside. + bool reset_loop_state{false}; + /// The representation of the current screen contents. screen_t screen; @@ -3875,6 +3878,11 @@ maybe_t reader_data_t::readline(int nchars_or_0) { force_exec_prompt_and_repaint = true; while (!rls.finished && !check_exit_loop_maybe_warning(this)) { + if (reset_loop_state) { + reset_loop_state = false; + rls.last_cmd = none(); + rls.complete_did_insert = false; + } // Perhaps update the termsize. This is cheap if it has not changed. update_termsize(); @@ -4113,6 +4121,7 @@ void reader_set_buffer(const wcstring &b, size_t pos) { data->pager.clear(); data->set_buffer_maintaining_pager(b, pos); + data->reset_loop_state = true; } size_t reader_get_cursor_pos() { diff --git a/tests/pexpects/complete.py b/tests/pexpects/complete.py index 6815bb657..ecada1dc6 100644 --- a/tests/pexpects/complete.py +++ b/tests/pexpects/complete.py @@ -48,3 +48,12 @@ send("echo fo\t ") send("\x07") sendline("bar") expect_re("foooo bar") + +sendline("bind \cg 'commandline -f cancel; commandline \"\"'") +send("echo fo\t") +expect_re("foooo") +send("\x07") +sendline("echo bar") +expect_re("\nbar") +sendline("echo fo\t") +expect_re("foooo")