fix position changes when commenting and cursor is before comment

This commit is contained in:
Anthony Sottile
2020-08-28 21:09:16 -07:00
parent eb26d93e03
commit fd9393c8b1
2 changed files with 16 additions and 1 deletions

View File

@@ -691,7 +691,7 @@ class File:
assert ws_match is not None
ws_len = len(ws_match[0])
self.buf[lineno] = f'{ws_match[0]}{prefix}{line[ws_len:]}'
if lineno == self.buf.y:
if lineno == self.buf.y and self.buf.x > ws_len:
self.buf.x += len(prefix)
@edit_action('comment', final=True)

View File

@@ -97,3 +97,18 @@ def test_add_comment_moves_cursor(run, ten_lines):
h.press_and_enter(':comment')
h.await_cursor_position(x=8, y=1)
def test_do_not_move_if_cursor_before_comment(run, tmpdir):
f = tmpdir.join('f')
f.write('\t\tfoo')
with run(str(f)) as h, and_exit(h):
h.press('Right')
h.await_cursor_position(x=4, y=1)
trigger_command_mode(h)
h.press_and_enter(':comment')
h.await_cursor_position(x=4, y=1)