Skip to content

Commit 5e45d33

Browse files
lieryanjonathanslenders
authored andcommitted
Set cursor position after replacement to last selected range
1 parent 862be13 commit 5e45d33

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pyvim/commands/commands.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ def substitute(editor, range_start, range_end, search, replace, flags):
713713
""" Substitute /search/ with /replace/ over a range of text """
714714
def get_line_index_iterator(cursor_position_row, range_start, range_end):
715715
if not range_start:
716+
assert not range_end
716717
range_start = range_end = cursor_position_row
717718
else:
718719
range_start = int(range_start) - 1
@@ -739,7 +740,8 @@ def get_transform_callback(search, replace, flags):
739740
transform_callback = get_transform_callback(search, replace, flags)
740741
new_text = buffer.transform_lines(line_index_iterator, transform_callback)
741742

742-
new_cursor_position_row = int(range_start) - 1 if range_start and not range_end else cursor_position_row
743+
assert len(line_index_iterator) >= 1
744+
new_cursor_position_row = line_index_iterator[-1]
743745

744746
# update text buffer
745747
buffer.document = Document(

tests/test_substitute.py

+4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ def test_substitute_range(editor, editor_buffer):
5555
assert 'Violet is blue,' in editor_buffer.buffer.text
5656
assert 'And so are you.' in editor_buffer.buffer.text
5757
# FIXME: vim would have set the cursor position on last substituted line
58+
# but we set the cursor position on the end_range even when there
59+
# is not substitution there
5860
# assert editor_buffer.buffer.cursor_position \
5961
# == editor_buffer.buffer.text.index('Violet')
62+
assert editor_buffer.buffer.cursor_position \
63+
== editor_buffer.buffer.text.index('Sugar')
6064

6165

6266
def test_substitute_range_boundaries(editor, editor_buffer):

0 commit comments

Comments
 (0)