Merge pull request #122 from asottile/backspace_blank_line_at_eof
fix backspacing an extra blank line at end of file
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user