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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user