summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorAndrew Eisenberg2012-01-26 00:29:35 (EST)
committer John Arthorne2012-01-27 17:42:07 (EST)
commit3182b98a3f620d2fae77473bbca7062e0cde31d5 (patch)
treed417e93853bb6f1a95daac3c695bb23b2ebf4766
parent91186e57188ab06b6f4980880872eb4c96ee1e8e (diff)
downloadorg.eclipse.orion.client-3182b98a3f620d2fae77473bbca7062e0cde31d5.zip
org.eclipse.orion.client-3182b98a3f620d2fae77473bbca7062e0cde31d5.tar.gz
org.eclipse.orion.client-3182b98a3f620d2fae77473bbca7062e0cde31d5.tar.bz2
Bug 347058. Incorporate up/down keys for resources navigation. Now, uo/down keys also work for favorites.
-rw-r--r--bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js64
1 files changed, 45 insertions, 19 deletions
diff --git a/bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js b/bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js
index 85d20f3..41a0827 100644
--- a/bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js
+++ b/bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js
@@ -79,27 +79,53 @@ var OpenResourceDialog = dojo.declare("orion.widgets.OpenResourceDialog", [dijit
}
});
dojo.connect(this,"onKeyPress",this,function(evt) {
- var links, currentFocus, currentSelectionIndex;
- if (evt.keyCode === dojo.keys.DOWN_ARROW && this.results) {
- links = dojo.query("a", this.results);
- currentFocus = dijit.getFocus();
- currentSelectionIndex = links.indexOf(currentFocus.node);
- if (currentSelectionIndex === -1) {
- dijit.focus(links[0]);
- } else if (currentSelectionIndex<links.length) {
- dijit.focus(links[currentSelectionIndex+1]);
- }
- dojo.stopEvent(evt);
- } else if (evt.keyCode === dojo.keys.UP_ARROW) {
+ var favlinks, links, text, currentFocus, favCurrentSelectionIndex, currentSelectionIndex;
+ var incrementFocus = function(currList, index, nextEntry) {
+ if (index < currList.length - 1) {
+ return currList[index+1];
+ } else {
+ return nextEntry;
+ }
+ };
+ var decrementFocus = function(currList, index, prevEntry) {
+ if (index > 0) {
+ return currList[index-1];
+ } else {
+ return prevEntry;
+ }
+ };
+
+ if (evt.keyCode === dojo.keys.DOWN_ARROW || evt.keyCode === dojo.keys.UP_ARROW) {
links = dojo.query("a", this.results);
+ favlinks = dojo.query("a", this.favresults);
currentFocus = dijit.getFocus();
currentSelectionIndex = links.indexOf(currentFocus.node);
- if (currentSelectionIndex < 1) {
- // jump to input element
- var text = this.resourceName && this.resourceName.get("textbox");
- dijit.focus(text);
- } else if (currentSelectionIndex > 0) {
- dijit.focus(links[currentSelectionIndex-1]);
+ favCurrentSelectionIndex = favlinks.indexOf(currentFocus.node);
+ if (evt.keyCode === dojo.keys.DOWN_ARROW) {
+ if (favCurrentSelectionIndex >= 0) {
+ dijit.focus(incrementFocus(favlinks, favCurrentSelectionIndex, links.length > 0 ? links[0] : favlinks[0]));
+ } else if (currentSelectionIndex >= 0) {
+ dijit.focus(incrementFocus(links, currentSelectionIndex, favlinks.length > 0 ? favlinks[0] : links[0]));
+ } else if (links.length > 0 || favlinks.length > 0) {
+ // coming from the text box
+ dijit.focus(incrementFocus(favlinks, -1, links[0]));
+ }
+ } else {
+ if (favCurrentSelectionIndex >= 0) {
+ // jump to text box if index === 0
+ text = this.resourceName && this.resourceName.get("textbox");
+ dijit.focus(decrementFocus(favlinks, favCurrentSelectionIndex, text));
+ } else if (currentSelectionIndex >= 0) {
+ // jump to text box if index === 0 and favlinks is empty
+ text = this.resourceName && this.resourceName.get("textbox");
+ dijit.focus(decrementFocus(links, currentSelectionIndex, favlinks.length > 0 ? favlinks[favlinks.length-1] : text));
+ } else if (links.length > 0) {
+ // coming from the text box go to end of list
+ dijit.focus(links[links.length-1]);
+ } else if (favlinks.length > 0) {
+ // coming from the text box go to end of list
+ dijit.focus(favlinks[favlinks.length-1]);
+ }
}
dojo.stopEvent(evt);
}
@@ -242,4 +268,4 @@ var OpenResourceDialog = dojo.declare("orion.widgets.OpenResourceDialog", [dijit
});
return OpenResourceDialog;
-}); \ No newline at end of file
+});