fix search history appending blank lines

This commit is contained in:
Anthony Sottile
2019-12-14 13:48:55 -08:00
parent 230e457e79
commit 070c1002f8
2 changed files with 14 additions and 2 deletions

View File

@@ -227,8 +227,10 @@ class Status:
yield
finally:
for k, v in self._history.items():
with open(os.path.join(history_dir, k), 'a+') as f:
f.write('\n'.join(v[self._history_orig_len[k]:]) + '\n')
new_history = v[self._history_orig_len[k]:]
if new_history:
with open(os.path.join(history_dir, k), 'a+') as f:
f.write('\n'.join(new_history) + '\n')
def update(self, status: str) -> None:
self._status = status

View File

@@ -296,3 +296,13 @@ def test_search_reverse_search_keeps_current_text_displayed():
h.press('^R')
h.await_text('search(reverse-search)``: ohai')
h.press('^C')
def test_search_history_extra_blank_lines(xdg_data_home):
with run() as h, and_exit(h):
h.press('^W')
h.press_and_enter('hello')
with run() as h, and_exit(h):
pass
contents = xdg_data_home.join('babi/history/search').read()
assert contents == 'hello\n'