Skip to content

Commit f3d521d

Browse files
committed
[Lib Manager] Avoid updating the UI at every keystroke
Fixes #8282
1 parent 2b11e94 commit f3d521d

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

app/src/cc/arduino/contributions/ui/FilterJTextField.java

+6-18
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import javax.swing.event.DocumentEvent;
3434
import javax.swing.event.DocumentListener;
3535
import java.awt.*;
36+
import java.awt.event.ActionEvent;
37+
import java.awt.event.ActionListener;
3638
import java.awt.event.FocusEvent;
3739
import java.awt.event.FocusListener;
3840

@@ -66,35 +68,21 @@ public void focusGained(FocusEvent focusEvent) {
6668
}
6769
});
6870

69-
getDocument().addDocumentListener(new DocumentListener() {
70-
public void removeUpdate(DocumentEvent e) {
71-
applyFilter();
72-
}
73-
74-
public void insertUpdate(DocumentEvent e) {
75-
applyFilter();
76-
}
77-
78-
public void changedUpdate(DocumentEvent e) {
71+
addActionListener(new ActionListener() {
72+
@Override
73+
public void actionPerformed(ActionEvent e) {
7974
applyFilter();
8075
}
8176
});
8277
}
8378

84-
private String lastFilter = "";
85-
86-
private void applyFilter() {
79+
public void applyFilter() {
8780
String filter = showingHint ? "" : getText();
8881
filter = filter.toLowerCase();
8982

9083
// Replace anything but 0-9, a-z, or : with a space
9184
filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");
9285

93-
// Fire event only if the filter is changed
94-
if (filter.equals(lastFilter))
95-
return;
96-
97-
lastFilter = filter;
9886
onFilter(filter.split(" "));
9987
}
10088

app/src/cc/arduino/contributions/ui/InstallerJDialog.java

+1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ public void setFilterText(String filterText) {
320320
listener.focusGained(new FocusEvent(filterField, FocusEvent.FOCUS_GAINED));
321321
}
322322
filterField.setText(filterText);
323+
filterField.applyFilter();
323324
}
324325

325326
public void selectDropdownItemByClassName(String dropdownItem) {

0 commit comments

Comments
 (0)