Skip to content

Commit 46880bd

Browse files
committed
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 f4e8a91 commit 46880bd

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
@@ -59,6 +59,12 @@ public boolean shouldContain(ContributedPlatform platform) {
5959
return platform.getArchitecture().equals(arch);
6060
}
6161

62+
public boolean contains(ContributedPlatform platform) {
63+
return (platform.getParentPackage().equals(packager)
64+
&& platform.getArchitecture().equals(arch)
65+
&& versions.contains(platform.getParsedVersion()));
66+
}
67+
6268
public void add(ContributedPlatform platform) {
6369
releases.add(platform);
6470
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
@@ -65,11 +65,21 @@ private void updateContributions() {
6565
+ platform.getBoards().stream()
6666
.map(ContributedBoard::getName)
6767
.collect(Collectors.joining(" "));
68+
69+
// Add all the versions of the same core, even if there's no match
70+
for (ContributedPlatformReleases contribution : contributions) {
71+
if (contribution.shouldContain(platform)) {
72+
addContribution(platform);
73+
continue;
74+
}
75+
}
76+
6877
if (!filter.test(platform)) {
6978
continue;
7079
}
7180
if (!stringContainsAll(compoundTargetSearchText, filters))
7281
continue;
82+
7383
addContribution(platform);
7484
}
7585
}
@@ -97,12 +107,16 @@ private boolean stringContainsAll(String string, String set[]) {
97107

98108
private void addContribution(ContributedPlatform platform) {
99109
for (ContributedPlatformReleases contribution : contributions) {
100-
if (!contribution.shouldContain(platform))
110+
if (!contribution.shouldContain(platform)) {
101111
continue;
112+
}
113+
if (contribution.contains(platform)) {
114+
// no duplicates
115+
return;
116+
}
102117
contribution.add(platform);
103118
return;
104119
}
105-
106120
contributions.add(new ContributedPlatformReleases(platform));
107121
}
108122

0 commit comments

Comments
 (0)