Skip to content

Commit

Permalink
Find/Replace overlay: immediate replace after selected text #2011
Browse files Browse the repository at this point in the history
The TextViewer implementation of IFindReplaceTargetExtension3.replaceSelection() does not perform
a replace operation if no preceeding find operation was called. To address this accepted
deviation from the interface's specification, this change forces the overlay to search for an initializing
word again so that the Editor can then later replace it if required.

fixes #2011
  • Loading branch information
Maximilian Wittmer authored and HeikoKlare committed Jul 15, 2024
1 parent 816820a commit be68f2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ private void updateFromTargetSelection() {
selectionText = FindReplaceDocumentAdapter.escapeForRegExPattern(selectionText);
}
searchBar.setText(selectionText);
findReplaceLogic.findAndSelect(findReplaceLogic.getTarget().getSelection().x, searchBar.getText());
}
searchBar.setSelection(0, searchBar.getText().length());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,18 @@ public void testActivateDialogSelectionActive_withRegExOptionActivated() {
assertThat(fTextViewer.getDocument().get(), is("test ;"));
}

@Test
public void testReplaceIfSelectedOnStart() {
openTextViewer("abcdefg");
fTextViewer.setSelection(new TextSelection(2, 2));
initializeFindReplaceUIForTextViewer();

dialog.setReplaceText("aa");
dialog.performReplace();

assertThat(fTextViewer.getDocument().get(), is("abaaefg"));
}

protected AccessType getDialog() {
return dialog;
}
Expand Down

0 comments on commit be68f2f

Please sign in to comment.