Don't include the bottom line of selection if blank
This commit is contained in:
2
babi.py
2
babi.py
@@ -1102,6 +1102,8 @@ class File:
|
||||
def sort_selection(self, margin: Margin) -> None:
|
||||
(s_y, _), (e_y, _) = self._get_selection()
|
||||
e_y = min(e_y + 1, len(self.lines) - 1)
|
||||
if self.lines[e_y - 1] == '':
|
||||
e_y -= 1
|
||||
self._sort(margin, s_y, e_y)
|
||||
|
||||
DISPATCH = {
|
||||
|
||||
@@ -42,3 +42,18 @@ def test_sort_selection_does_not_include_eof(run, unsorted):
|
||||
h.await_cursor_position(x=0, y=1)
|
||||
h.press('^S')
|
||||
assert unsorted.read() == 'a\nb\nc\nd\n'
|
||||
|
||||
|
||||
def test_sort_does_not_include_blank_line_after(run, tmpdir):
|
||||
f = tmpdir.join('f')
|
||||
f.write('b\na\n\nd\nc\n')
|
||||
|
||||
with run(str(f)) as h, and_exit(h):
|
||||
h.press('S-Down')
|
||||
h.press('S-Down')
|
||||
trigger_command_mode(h)
|
||||
h.press_and_enter(':sort')
|
||||
h.await_text('sorted!')
|
||||
h.await_cursor_position(x=0, y=1)
|
||||
h.press('^S')
|
||||
assert f.read() == 'a\nb\n\nd\nc\n'
|
||||
|
||||
Reference in New Issue
Block a user