Skip to content

Commit cec4f41

Browse files
facchinmcmaglie
authored andcommitted
Board Manager: searching returns also near matches
The original filter would only populate the contribution list with perfect matches. Previously, if a core was installed but didn't match the search it wouldn't appear in the results (due to a board being added or the description changed); the user could then install (not upgrade) the core, triggering a confusing situation. When moving to arduino-cli backend we should take care of this issue, at least visually (the cli logic would correctly update/downgrade the core)
1 parent 96bd671 commit cec4f41

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Diff for: app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public boolean shouldContain(ContributedPlatform platform) {
6161
return platform.getArchitecture().equals(arch);
6262
}
6363

64+
public boolean contains(ContributedPlatform platform) {
65+
return (platform.getParentPackage().equals(packager)
66+
&& platform.getArchitecture().equals(arch)
67+
&& versions.contains(platform.getParsedVersion()));
68+
}
69+
6470
public void add(ContributedPlatform platform) {
6571
releases.add(platform);
6672
String version = platform.getParsedVersion();

Diff for: app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,21 @@ private void updateContributions() {
6666
+ platform.getBoards().stream()
6767
.map(ContributedBoard::getName)
6868
.collect(Collectors.joining(" "));
69+
70+
// Add all the versions of the same core, even if there's no match
71+
for (ContributedPlatformReleases contribution : contributions) {
72+
if (contribution.shouldContain(platform)) {
73+
addContribution(platform);
74+
continue;
75+
}
76+
}
77+
6978
if (!filter.test(platform)) {
7079
continue;
7180
}
7281
if (!stringContainsAll(compoundTargetSearchText, filters))
7382
continue;
83+
7484
addContribution(platform);
7585
}
7686
}
@@ -110,12 +120,16 @@ private boolean stringContainsAll(String string, String set[]) {
110120

111121
private void addContribution(ContributedPlatform platform) {
112122
for (ContributedPlatformReleases contribution : contributions) {
113-
if (!contribution.shouldContain(platform))
123+
if (!contribution.shouldContain(platform)) {
114124
continue;
125+
}
126+
if (contribution.contains(platform)) {
127+
// no duplicates
128+
return;
129+
}
115130
contribution.add(platform);
116131
return;
117132
}
118-
119133
contributions.add(new ContributedPlatformReleases(platform));
120134
}
121135

0 commit comments

Comments
 (0)