Improve key navigation for search results

Select an item by default when the search results are displayed.

Enable moving from one section of search results to another with key navigation.

Reset the selection when the search is updated or a new page is displayed
or the transition between viewing multiple sections and viewing just one is made.
This commit is contained in:
Marina Zhurakhinskaya 2009-09-01 16:24:47 -04:00
parent 687814b6c6
commit 90381ceea2
2 changed files with 47 additions and 24 deletions

View File

@ -572,6 +572,14 @@ Dash.prototype = {
this._appSearchHeader.countText.text = this._appSearchResultArea.display.getMatchedItemsCount() + ""; this._appSearchHeader.countText.text = this._appSearchResultArea.display.getMatchedItemsCount() + "";
this._docSearchHeader.countText.text = this._docSearchResultArea.display.getMatchedItemsCount() + ""; this._docSearchHeader.countText.text = this._docSearchResultArea.display.getMatchedItemsCount() + "";
if (this._appSearchResultArea.display.hasItems() && !this._getOnlyDocSearchShown()) {
this._appSearchResultArea.display.selectFirstItem();
this._docSearchResultArea.display.unsetSelected();
} else if (this._docSearchResultArea.display.hasItems() && !this._getOnlyAppSearchShown()) {
this._docSearchResultArea.display.selectFirstItem();
this._appSearchResultArea.display.unsetSelected();
}
return false; return false;
})); }));
})); }));
@ -607,22 +615,32 @@ Dash.prototype = {
// too, but there doesn't seem to be any flickering if we first select // too, but there doesn't seem to be any flickering if we first select
// something in one display, but then unset the selection, and move // something in one display, but then unset the selection, and move
// it to the other display, so it's ok to do that. // it to the other display, so it's ok to do that.
if (this._docSearchResultArea.display.hasSelected()) if (this._appSearchResultArea.display.hasSelected()) {
this._docSearchResultArea.display.selectUp(); if (!this._appSearchResultArea.display.selectUp() && this._docSearchResultArea.display.hasItems() && !this._getOnlyAppSearchShown()) {
else if (this._appSearchResultArea.display.hasItems()) this._docSearchResultArea.display.selectLastItem();
this._appSearchResultArea.display.selectUp(); this._appSearchResultArea.display.unsetSelected();
else }
this._docSearchResultArea.display.selectUp(); } else if (this._docSearchResultArea.display.hasSelected()) {
if (!this._docSearchResultArea.display.selectUp() && this._appSearchResultArea.display.hasItems() && !this._getOnlyDocSearchShown()) {
this._appSearchResultArea.display.selectLastItem();
this._docSearchResultArea.display.unsetSelected();
}
}
return true; return true;
} else if (symbol == Clutter.Down) { } else if (symbol == Clutter.Down) {
if (!this._searchActive) if (!this._searchActive)
return true; return true;
if (this._docSearchResultArea.display.hasSelected()) if (this._appSearchResultArea.display.hasSelected()) {
this._docSearchResultArea.display.selectDown(); if (!this._appSearchResultArea.display.selectDown() && this._docSearchResultArea.display.hasItems() && !this._getOnlyAppSearchShown()) {
else if (this._appSearchResultArea.display.hasItems()) this._docSearchResultArea.display.selectFirstItem();
this._appSearchResultArea.display.selectDown(); this._appSearchResultArea.display.unsetSelected();
else }
this._docSearchResultArea.display.selectDown(); } else if (this._docSearchResultArea.display.hasSelected()) {
if (!this._docSearchResultArea.display.selectDown() && this._appSearchResultArea.display.hasItems() && !this._getOnlyDocSearchShown()) {
this._appSearchResultArea.display.selectFirstItem();
this._docSearchResultArea.display.unsetSelected();
}
}
return true; return true;
} }
return false; return false;
@ -788,6 +806,8 @@ Dash.prototype = {
} else { } else {
this._appSearchHeader.actor.hide(); this._appSearchHeader.actor.hide();
this._appSearchResultArea.actor.hide(); this._appSearchResultArea.actor.hide();
this._appSearchResultArea.display.unsetSelected();
this._docSearchResultArea.display.selectFirstItem();
this._docSearchResultArea.controlBox.show(); this._docSearchResultArea.controlBox.show();
this._docSearchHeader.setShowTooltip(false); this._docSearchHeader.setShowTooltip(false);
} }
@ -803,6 +823,8 @@ Dash.prototype = {
} else { } else {
this._docSearchHeader.actor.hide(); this._docSearchHeader.actor.hide();
this._docSearchResultArea.actor.hide(); this._docSearchResultArea.actor.hide();
this._docSearchResultArea.display.unsetSelected();
this._appSearchResultArea.display.selectFirstItem();
this._appSearchResultArea.controlBox.show(); this._appSearchResultArea.controlBox.show();
this._appSearchHeader.setShowTooltip(false); this._appSearchHeader.setShowTooltip(false);
} }

View File

@ -426,7 +426,11 @@ GenericDisplay.prototype = {
// Returns true if the display has any displayed items. // Returns true if the display has any displayed items.
hasItems: function() { hasItems: function() {
return this._list.displayedCount > 0; // TODO: figure out why this._list.displayedCount is returning a
// positive number when this._mathedItems.length is 0
// This can be triggered if a search string is entered for which there are no matches.
// log("this._mathedItems.length: " + this._matchedItems.length + " this._list.displayedCount " + this._list.displayedCount);
return this._matchedItems.length > 0;
}, },
getMatchedItemsCount: function() { getMatchedItemsCount: function() {
@ -457,6 +461,10 @@ GenericDisplay.prototype = {
// Displays the page specified by the pageNumber argument. // Displays the page specified by the pageNumber argument.
displayPage: function(pageNumber) { displayPage: function(pageNumber) {
// Cleanup from the previous selection, but don't unset this._selectedIndex
if (this.hasSelected()) {
this._findDisplayedByIndex(this._selectedIndex).markSelected(false);
}
this._list.page = pageNumber; this._list.page = pageNumber;
}, },
@ -698,7 +706,6 @@ GenericDisplay.prototype = {
*/ */
_updateDisplayControl: function(resetDisplayControl) { _updateDisplayControl: function(resetDisplayControl) {
if (resetDisplayControl) { if (resetDisplayControl) {
this._selectedIndex = -1;
this.displayControl.remove_all(); this.displayControl.remove_all();
let nPages = this._list.n_pages; let nPages = this._list.n_pages;
let pageNumber = this._list.page; let pageNumber = this._list.page;
@ -730,6 +737,9 @@ GenericDisplay.prototype = {
} }
} }
} }
if (this.hasSelected()) {
this.selectFirstItem();
}
}, },
// Returns a display item based on its index in the ordering of the // Returns a display item based on its index in the ordering of the
@ -754,17 +764,8 @@ GenericDisplay.prototype = {
// Selects (e.g. highlights) a display item at the provided index, // Selects (e.g. highlights) a display item at the provided index,
// updates this.selectedItemDetails actor, and emits 'selected' signal. // updates this.selectedItemDetails actor, and emits 'selected' signal.
_selectIndex: function(index) { _selectIndex: function(index) {
if (index >= this._list.displayedCount)
return
// If the item is already selected, all we do is toggling the details pane.
if (this._selectedIndex == index && index >= 0) {
this.emit('details', index);
return;
}
// Cleanup from the previous item // Cleanup from the previous item
if (this._selectedIndex >= 0) { if (this.hasSelected()) {
this._findDisplayedByIndex(this._selectedIndex).markSelected(false); this._findDisplayedByIndex(this._selectedIndex).markSelected(false);
} }