Revision: 7814
Author: [email protected]
Date: Mon Mar 29 12:51:43 2010
Log: Fix the bug where you cannot use up arrow to enter the suggestions box
Review at http://gwt-code-reviews.appspot.com/239801
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=7814
Modified:
/trunk/user/src/com/google/gwt/user/client/ui/SuggestBox.java
/trunk/user/test/com/google/gwt/user/client/ui/SuggestBoxTest.java
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/SuggestBox.java Fri Mar
19 08:12:41 2010
+++ /trunk/user/src/com/google/gwt/user/client/ui/SuggestBox.java Mon Mar
29 09:42:22 2010
@@ -366,6 +366,8 @@
// Make sure that the menu is actually showing. These keystrokes
// are only relevant when choosing a suggestion.
if (isSuggestionListShowing()) {
+ // If nothing is selected, getSelectedItemIndex will return -1 and
we
+ // will select index 0 (the first item) by default.
suggestionMenu.selectItem(suggestionMenu.getSelectedItemIndex() +
1);
}
}
@@ -375,7 +377,17 @@
// Make sure that the menu is actually showing. These keystrokes
// are only relevant when choosing a suggestion.
if (isSuggestionListShowing()) {
- suggestionMenu.selectItem(suggestionMenu.getSelectedItemIndex() -
1);
+ // if nothing is selected, then we should select the last
suggestion by
+ // default. This is because, in some cases, the suggestions menu
will
+ // appear above the text box rather than below it (for example, if
the
+ // text box is at the bottom of the window and the suggestions
will not
+ // fit below the text box). In this case, users would expect to be
able
+ // to use the up arrow to navigate to the suggestions.
+ if (suggestionMenu.getSelectedItemIndex() == -1) {
+ suggestionMenu.selectItem(suggestionMenu.getNumItems() - 1);
+ } else {
+ suggestionMenu.selectItem(suggestionMenu.getSelectedItemIndex()
- 1);
+ }
}
}
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/SuggestBoxTest.java Thu
Feb 4 04:43:03 2010
+++ /trunk/user/test/com/google/gwt/user/client/ui/SuggestBoxTest.java Mon
Mar 29 09:42:22 2010
@@ -170,6 +170,41 @@
assertEquals("A", display.getSuggestion(0).getReplacementString());
assertEquals("B", display.getSuggestion(1).getReplacementString());
}
+
+ public void testSuggestionSelection() {
+ MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
+ oracle.setDefaultSuggestionsFromText(Arrays.asList("A", "B"));
+ TestSuggestionDisplay display = new TestSuggestionDisplay();
+ SuggestBox box = new SuggestBox(oracle, new TextBox(), display);
+ box.setAutoSelectEnabled(false);
+ RootPanel.get().add(box);
+ box.showSuggestionList();
+
+ // If nothing is selected, moving down will select the first item
+ assertNull(display.getCurrentSelection());
+ display.moveSelectionDown();
+ assertEquals("A",
display.getCurrentSelection().getReplacementString());
+
+ // Once something is selected, selections are made as expected, but we
do
+ // not move outside the box
+ display.moveSelectionDown();
+ assertEquals("B",
display.getCurrentSelection().getReplacementString());
+ display.moveSelectionDown();
+ assertEquals("B",
display.getCurrentSelection().getReplacementString());
+ display.moveSelectionUp();
+ assertEquals("A",
display.getCurrentSelection().getReplacementString());
+ display.moveSelectionUp();
+ assertEquals("A",
display.getCurrentSelection().getReplacementString());
+
+ // Reset the suggestions so that nothing is selected again
+ display.hideSuggestions();
+ box.showSuggestionList();
+ assertNull(display.getCurrentSelection());
+
+ // If nothing is selected, moving up will select the last item
+ display.moveSelectionUp();
+ assertEquals("B",
display.getCurrentSelection().getReplacementString());
+ }
public void testShowFirst() {
SuggestBox box = createSuggestBox();
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
To unsubscribe from this group, send email to
google-web-toolkit-contributors+unsubscribegooglegroups.com or reply to this email with
the words "REMOVE ME" as the subject.