Merge pull request #91 from asottile/fix_cursor_position_comment

fix position changes when commenting and cursor is before comment
This commit is contained in:
Anthony Sottile
2020-08-28 21:17:27 -07:00
committed by GitHub
2 changed files with 16 additions and 1 deletions

View File

@@ -691,7 +691,7 @@ class File:
assert ws_match is not None assert ws_match is not None
ws_len = len(ws_match[0]) ws_len = len(ws_match[0])
self.buf[lineno] = f'{ws_match[0]}{prefix}{line[ws_len:]}' 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) self.buf.x += len(prefix)
@edit_action('comment', final=True) @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.press_and_enter(':comment')
h.await_cursor_position(x=8, y=1) 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)