Skip to content

Commit 496a512

Browse files
lieryanjonathanslenders
authored andcommitted
Fix exception on repeat substitution without substitution
1 parent a49de3c commit 496a512

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pyvim/commands/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ def get_transform_callback(search, replace, flags):
734734
if not search:
735735
search = search_state.text
736736

737-
if editor.last_substitute_text and replace is None:
737+
if replace is None:
738738
replace = editor.last_substitute_text
739739

740740
line_index_iterator = get_line_index_iterator(cursor_position_row, range_start, range_end)

tests/test_substitute.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ def test_substitute_with_repeat_last_substitution(editor, editor_buffer):
8888
assert 'Rose is Rose' in editor_buffer.buffer.text
8989

9090

91+
def test_substitute_with_repeat_last_substitution_without_previous_substitution(editor, editor_buffer):
92+
original_text = 'Violet is blue\n'
93+
given_sample_text(editor_buffer, original_text)
94+
95+
handle_command(editor, ':s')
96+
assert original_text in editor_buffer.buffer.text
97+
98+
editor.application.current_search_state.text = 'blue'
99+
100+
handle_command(editor, ':s')
101+
assert 'Violet is \n' in editor_buffer.buffer.text
102+
103+
91104
def test_substitute_flags_empty_flags(editor, editor_buffer):
92105
given_sample_text(editor_buffer, 'Violet is Violet\n')
93106
handle_command(editor, ':s/Violet/Rose/')

0 commit comments

Comments
 (0)