Skip to content

Commit d9c6234

Browse files
lieryanjonathanslenders
authored andcommitted
Fix cursor position after :substitute with line number
1 parent 103057c commit d9c6234

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pyvim/commands/commands.py

+1
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ def substitute(editor, range_start, range_end, search, replace, flags):
719719
current_row = buffer.document.cursor_position_row
720720

721721
if not range_end:
722+
current_row = (int(range_start) - 1) if range_start else current_row
722723
range_end = range_start
723724
if range_start and range_end:
724725
line_index_iterator = range(int(range_start) - 1, int(range_end))

tests/test_substitute.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ def test_substitute_single_line(editor, editor_buffer):
4141
assert 'Roses are red,' in editor_buffer.buffer.text
4242
assert 'Violet is blue,' in editor_buffer.buffer.text
4343
assert 'And so are you.' in editor_buffer.buffer.text
44-
# FIXME: vim would have set the cursor position on the substituted line
45-
# assert editor_buffer.buffer.cursor_position \
46-
# == editor_buffer.buffer.text.index('Violet')
44+
assert editor_buffer.buffer.cursor_position \
45+
== editor_buffer.buffer.text.index('Violet')
4746

4847

4948
def test_substitute_range(editor, editor_buffer):

0 commit comments

Comments
 (0)