From de57f2cef2e5fb037d2a468c0c2889ee3fed09d9 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 8 Jan 2020 21:10:53 -0800 Subject: [PATCH] Fix search default when equal to last history entry --- babi.py | 2 +- tests/search_test.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/babi.py b/babi.py index 7bc4545..e699a9f 100644 --- a/babi.py +++ b/babi.py @@ -1483,7 +1483,7 @@ class Screen: history_lst = self.history.data[history] if not history_lst or history_lst[-1] != ret: history_lst.append(ret) - self.history.prev[history] = ret + self.history.prev[history] = ret elif default_prev and history in self.history.prev: return self.history.prev[history] diff --git a/tests/search_test.py b/tests/search_test.py index 3be8dd7..649c266 100644 --- a/tests/search_test.py +++ b/tests/search_test.py @@ -203,6 +203,19 @@ def test_search_multiple_sessions_append_to_history(run, xdg_data_home): ) +def test_search_default_same_as_prev_history(run, xdg_data_home, ten_lines): + xdg_data_home.join('babi/history/search').ensure().write('line\n') + + with run(str(ten_lines)) as h, and_exit(h): + h.press('^W') + h.press_and_enter('line') + h.await_cursor_position(x=0, y=2) + h.press('^W') + h.await_text('search [line]:') + h.press('Enter') + h.await_cursor_position(x=0, y=3) + + @pytest.mark.parametrize('key', ('BSpace', '^H')) def test_search_reverse_search_history_backspace(run, xdg_data_home, key): xdg_data_home.join('babi/history/search').ensure().write(