fix search history appending blank lines
This commit is contained in:
6
babi.py
6
babi.py
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user