fix backspacing an extra blank line at end of file

This commit is contained in:
Anthony Sottile
2021-01-18 14:57:34 -08:00
parent 8245ee56a5
commit 09643b0f80
2 changed files with 17 additions and 1 deletions

View File

@@ -476,7 +476,11 @@ class File:
if self.buf.y == 0 and self.buf.x == 0:
pass
# backspace at the end of the file does not change the contents
elif self.buf.y == len(self.buf) - 1:
elif (
self.buf.y == len(self.buf) - 1 and
# still allow backspace if there are 2+ blank lines
self.buf[self.buf.y - 1] != ''
):
self.buf.left(margin)
# at the beginning of the line, we join the current line and
# the previous line

View File

@@ -50,6 +50,18 @@ def test_backspace_at_end_of_file_still_allows_scrolling_down(run, tmpdir):
h.await_text_missing('*')
def test_backspace_deletes_newline_at_end_of_file(run, tmpdir):
f = tmpdir.join('f')
f.write('foo\n\n')
with run(str(f)) as h, and_exit(h):
h.press('^End')
h.press('BSpace')
h.press('^S')
assert f.read() == 'foo\n'
@pytest.mark.parametrize('key', ('BSpace', '^H'))
def test_backspace_deletes_text(run, tmpdir, key):
f = tmpdir.join('f')