Skip to content

Commit

Permalink
Fix exception on repeat substitution without substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
lieryan authored and jonathanslenders committed Mar 6, 2020
1 parent a49de3c commit 496a512
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyvim/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ def get_transform_callback(search, replace, flags):
if not search:
search = search_state.text

if editor.last_substitute_text and replace is None:
if replace is None:
replace = editor.last_substitute_text

line_index_iterator = get_line_index_iterator(cursor_position_row, range_start, range_end)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_substitute.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ def test_substitute_with_repeat_last_substitution(editor, editor_buffer):
assert 'Rose is Rose' in editor_buffer.buffer.text


def test_substitute_with_repeat_last_substitution_without_previous_substitution(editor, editor_buffer):
original_text = 'Violet is blue\n'
given_sample_text(editor_buffer, original_text)

handle_command(editor, ':s')
assert original_text in editor_buffer.buffer.text

editor.application.current_search_state.text = 'blue'

handle_command(editor, ':s')
assert 'Violet is \n' in editor_buffer.buffer.text


def test_substitute_flags_empty_flags(editor, editor_buffer):
given_sample_text(editor_buffer, 'Violet is Violet\n')
handle_command(editor, ':s/Violet/Rose/')
Expand Down

0 comments on commit 496a512

Please sign in to comment.