Skip to content

Commit

Permalink
Refine logic to avoid filtering if no active filters
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohnstn authored and iloveeclipse committed Apr 27, 2023
1 parent 47d3f1a commit daa9274
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.eclipse.search.internal.ui.text;

import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -225,13 +226,26 @@ private boolean isUnfiltered(FileMatch m) {
@Override
public synchronized void elementsChanged(Object[] updatedElements) {
boolean singleElement = updatedElements.length == 1;
Set<LineElement> lineMatches = Arrays.stream(updatedElements).filter(LineElement.class::isInstance)
Set<LineElement> lineMatches = Collections.emptySet();
// if we have active match filters, we should only use non-filtered FileMatch
// objects
// to collect LineElements to update
if (fResult.getActiveMatchFilters().length > 0) {
lineMatches = Arrays.stream(updatedElements).filter(LineElement.class::isInstance)
// only for distinct files:
.map(u -> ((LineElement) u).getParent()).distinct()
// query matches:
.map(fResult::getMatchSet).flatMap(FileTreeContentProvider::toStream)
.map(m -> ((FileMatch) m)).filter(this::isUnfiltered).map(m -> m.getLineElement())
.collect(Collectors.toSet());
} else {
lineMatches = Arrays.stream(updatedElements).filter(LineElement.class::isInstance)
// only for distinct files:
.map(u -> ((LineElement) u).getParent()).distinct()
// query matches:
.map(fResult::getMatchSet).flatMap(FileTreeContentProvider::toStream)
.map(m -> ((FileMatch) m).getLineElement()).collect(Collectors.toSet());
}
try {
for (Object updatedElement : updatedElements) {
if (!(updatedElement instanceof LineElement)) {
Expand Down

0 comments on commit daa9274

Please sign in to comment.