From: Artur Signell Date: Mon, 14 Nov 2011 11:25:22 +0000 (+0000) Subject: #7739 Split enter handling for input field and for popup X-Git-Tag: 7.0.0.alpha1~225^2~3^2~49 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c8c3d929dd68e2631d7c4237122da5fb98dad7b9;p=vaadin-framework.git #7739 Split enter handling for input field and for popup svn changeset:21988/svn branch:6.7 --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java index e0b7880a9e..db1ff61c61 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java @@ -1339,27 +1339,7 @@ public class VFilterSelect extends Composite implements Paintable, Field, */ public void onKeyDown(KeyDownEvent event) { if (enabled && !readonly) { - if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { - // Same reaction to enter no matter on whether the popup is open - if (suggestionPopup.isAttached()) { - filterOptions(currentPage); - } else if (currentSuggestion != null - && tb.getText().equals( - currentSuggestion.getReplacementString())) { - // Retain behavior from #6686 by returning without stopping - // propagation if there's nothing to do - return; - } - if (currentSuggestions.size() == 1 && !allowNewItem) { - // If there is only one suggestion, select that - suggestionPopup.menu.selectItem(suggestionPopup.menu - .getItems().get(0)); - } - suggestionPopup.menu.doSelectedItemAction(); - - event.stopPropagation(); - return; - } else if (suggestionPopup.isAttached()) { + if (suggestionPopup.isAttached()) { popupKeyDown(event); } else { inputFieldKeyDown(event); @@ -1391,6 +1371,27 @@ public class VFilterSelect extends Composite implements Paintable, Field, filterOptions(currentPage, tb.getText()); } break; + case KeyCodes.KEY_ENTER: + /* + * This only handles the case when new items is allowed, a text is + * entered, the popup opener button is clicked to close the popup + * and enter is then pressed (see #7560). + */ + if (!allowNewItem) { + return; + } + + if (currentSuggestion != null + && tb.getText().equals( + currentSuggestion.getReplacementString())) { + // Retain behavior from #6686 by returning without stopping + // propagation if there's nothing to do + return; + } + suggestionPopup.menu.doSelectedItemAction(); + + event.stopPropagation(); + break; } } @@ -1428,12 +1429,22 @@ public class VFilterSelect extends Composite implements Paintable, Field, event.stopPropagation(); break; case KeyCodes.KEY_TAB: - if (suggestionPopup.isAttached()) { - tabPressedWhenPopupOpen = true; - filterOptions(currentPage); - } + tabPressedWhenPopupOpen = true; + filterOptions(currentPage); // onBlur() takes care of the rest break; + case KeyCodes.KEY_ENTER: + filterOptions(currentPage); + + if (currentSuggestions.size() == 1 && !allowNewItem) { + // If there is only one suggestion, select that + suggestionPopup.menu.selectItem(suggestionPopup.menu.getItems() + .get(0)); + } + suggestionPopup.menu.doSelectedItemAction(); + + event.stopPropagation(); + break; } }