Skip to content

Commit e3ca9fc

Browse files
committed
changed to ignore filtering on comboboxchanges instead of only filtering if typed because of event sequencing problems on backspace
1 parent bdd8c00 commit e3ca9fc

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/main/java/de/doubleslash/keeptime/view/ManageWorkController.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class ManageWorkController {
7575
@FXML
7676
private ComboBox<Project> projectComboBox;
7777

78-
private boolean userInteraction;
78+
private boolean comboChange;
7979

8080
public void setModel(final Model model) {
8181
this.model = model;
@@ -217,29 +217,36 @@ public Project fromString(final String string) {
217217
// needs to set again because editable is ignored from fxml because of custom preselection
218218
projectComboBox.setEditable(true);
219219

220-
projectComboBox.getEditor().setOnKeyTyped((e) -> {
221-
userInteraction = true;
220+
projectComboBox.valueProperty().addListener(new ChangeListener<Project>() {
221+
222+
@Override
223+
public void changed(final ObservableValue<? extends Project> observable, final Project oldValue,
224+
final Project newValue) {
225+
comboChange = true;
226+
227+
}
222228
});
223229

224230
projectComboBox.getEditor().textProperty().addListener(new ChangeListener<String>() {
225231

226232
@Override
227233
public void changed(final ObservableValue<? extends String> observable, final String oldValue,
228234
final String newValue) {
235+
LOG.debug("text Changed");
229236

230-
if (userInteraction) {
231-
userInteraction = false;
232-
233-
// needed to avoid exception on empty textfield https://bugs.openjdk.java.net/browse/JDK-8081700
234-
Platform.runLater(() -> {
235-
LOG.debug("Value:" + newValue);
236-
projectComboBox.hide();
237-
projectComboBox.setItems(model.getAllProjects().filtered(
238-
(project) -> ProjectsListViewController.doesProjectMatchSearchFilter(newValue, project)));
239-
projectComboBox.show();
240-
});
241-
237+
// ignore selectionChanges
238+
if (comboChange == true) {
239+
comboChange = false;
240+
return;
242241
}
242+
// needed to avoid exception on empty textfield https://bugs.openjdk.java.net/browse/JDK-8081700
243+
Platform.runLater(() -> {
244+
LOG.debug("Value:" + newValue);
245+
projectComboBox.hide();
246+
projectComboBox.setItems(model.getAllProjects().filtered(
247+
(project) -> ProjectsListViewController.doesProjectMatchSearchFilter(newValue, project)));
248+
projectComboBox.show();
249+
});
243250

244251
}
245252
});

0 commit comments

Comments
 (0)