Skip to content

Commit 9b509c0

Browse files
authored
Merge pull request arduino#11096 from facchinm/loose_filter_on_boards
Board Manager: searching returns also near matches
2 parents 96bd671 + aef6d2a commit 9b509c0

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,17 @@ public void updateIndexFilter(String[] filters,
6060

6161
private void updateContributions() {
6262
contributions.clear();
63+
64+
// Generate ContributedPlatformReleases from all platform releases
6365
for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) {
6466
for (ContributedPlatform platform : pack.getPlatforms()) {
67+
addContribution(platform);
68+
}
69+
}
70+
71+
// Filter ContributedPlatformReleases based on search terms
72+
contributions.removeIf(releases -> {
73+
for (ContributedPlatform platform : releases.releases) {
6574
String compoundTargetSearchText = platform.getName() + "\n"
6675
+ platform.getBoards().stream()
6776
.map(ContributedBoard::getName)
@@ -71,9 +80,12 @@ private void updateContributions() {
7180
}
7281
if (!stringContainsAll(compoundTargetSearchText, filters))
7382
continue;
74-
addContribution(platform);
83+
return false;
7584
}
76-
}
85+
return true;
86+
});
87+
88+
// Sort ContributedPlatformReleases and put deprecated platforms to the bottom
7789
Collections.sort(contributions, (x,y)-> {
7890
if (x.isDeprecated() != y.isDeprecated()) {
7991
return x.isDeprecated() ? 1 : -1;
@@ -86,6 +98,7 @@ private void updateContributions() {
8698
}
8799
return x1.getName().compareToIgnoreCase(y1.getName());
88100
});
101+
89102
fireTableDataChanged();
90103
}
91104

@@ -110,12 +123,12 @@ private boolean stringContainsAll(String string, String set[]) {
110123

111124
private void addContribution(ContributedPlatform platform) {
112125
for (ContributedPlatformReleases contribution : contributions) {
113-
if (!contribution.shouldContain(platform))
126+
if (!contribution.shouldContain(platform)) {
114127
continue;
128+
}
115129
contribution.add(platform);
116130
return;
117131
}
118-
119132
contributions.add(new ContributedPlatformReleases(platform));
120133
}
121134

0 commit comments

Comments
 (0)