Skip to content

Commit 7c69e19

Browse files
Maximilian WittmerMaximilian Wittmer
authored andcommitted
FindReplaceLogic/selectAll: don't set selection after every result
now, select all finds all the indices it needs to find and only sets the selection at the very end of the select all operation.
1 parent 5f931ee commit 7c69e19

File tree

1 file changed

+9
-8
lines changed
  • bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace

1 file changed

+9
-8
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogic.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,16 +405,17 @@ private void executeWithReplaceAllEnabled(Runnable runnable) {
405405
* @return the number of selected elements
406406
*/
407407
private int selectAll(String findString) {
408-
List<Point> selections = new ArrayList<>();
408+
List<IRegion> selections = new ArrayList<>();
409409
executeInForwardMode(() -> {
410-
Point currentSeletion = new Point(0, 0);
411-
while (findAndSelect(currentSeletion.x + currentSeletion.y, findString) != -1) {
412-
currentSeletion = target.getSelection();
413-
selections.add(currentSeletion);
414-
}
410+
final int searchStringLength = findString.length();
411+
final int firstIndex = findIndex(findString, 0);
412+
int index = firstIndex;
413+
do {
414+
index = findIndex(findString, index + searchStringLength);
415+
selections.add(new Region(index, searchStringLength));
416+
} while (index != firstIndex && index != -1);
415417
if (target instanceof IFindReplaceTargetExtension4 selectableTarget) {
416-
IRegion[] selectedRegions = selections.stream().map(selection -> new Region(selection.x, selection.y))
417-
.toArray(IRegion[]::new);
418+
IRegion[] selectedRegions = selections.toArray(IRegion[]::new);
418419
selectableTarget.setSelection(selectedRegions);
419420
}
420421
});

0 commit comments

Comments
 (0)