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:
parent
687814b6c6
commit
90381ceea2
@ -572,6 +572,14 @@ Dash.prototype = {
|
||||
this._appSearchHeader.countText.text = this._appSearchResultArea.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;
|
||||
}));
|
||||
}));
|
||||
@ -607,22 +615,32 @@ Dash.prototype = {
|
||||
// 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
|
||||
// it to the other display, so it's ok to do that.
|
||||
if (this._docSearchResultArea.display.hasSelected())
|
||||
this._docSearchResultArea.display.selectUp();
|
||||
else if (this._appSearchResultArea.display.hasItems())
|
||||
this._appSearchResultArea.display.selectUp();
|
||||
else
|
||||
this._docSearchResultArea.display.selectUp();
|
||||
if (this._appSearchResultArea.display.hasSelected()) {
|
||||
if (!this._appSearchResultArea.display.selectUp() && this._docSearchResultArea.display.hasItems() && !this._getOnlyAppSearchShown()) {
|
||||
this._docSearchResultArea.display.selectLastItem();
|
||||
this._appSearchResultArea.display.unsetSelected();
|
||||
}
|
||||
} 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;
|
||||
} else if (symbol == Clutter.Down) {
|
||||
if (!this._searchActive)
|
||||
return true;
|
||||
if (this._docSearchResultArea.display.hasSelected())
|
||||
this._docSearchResultArea.display.selectDown();
|
||||
else if (this._appSearchResultArea.display.hasItems())
|
||||
this._appSearchResultArea.display.selectDown();
|
||||
else
|
||||
this._docSearchResultArea.display.selectDown();
|
||||
if (this._appSearchResultArea.display.hasSelected()) {
|
||||
if (!this._appSearchResultArea.display.selectDown() && this._docSearchResultArea.display.hasItems() && !this._getOnlyAppSearchShown()) {
|
||||
this._docSearchResultArea.display.selectFirstItem();
|
||||
this._appSearchResultArea.display.unsetSelected();
|
||||
}
|
||||
} 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 false;
|
||||
@ -788,6 +806,8 @@ Dash.prototype = {
|
||||
} else {
|
||||
this._appSearchHeader.actor.hide();
|
||||
this._appSearchResultArea.actor.hide();
|
||||
this._appSearchResultArea.display.unsetSelected();
|
||||
this._docSearchResultArea.display.selectFirstItem();
|
||||
this._docSearchResultArea.controlBox.show();
|
||||
this._docSearchHeader.setShowTooltip(false);
|
||||
}
|
||||
@ -803,6 +823,8 @@ Dash.prototype = {
|
||||
} else {
|
||||
this._docSearchHeader.actor.hide();
|
||||
this._docSearchResultArea.actor.hide();
|
||||
this._docSearchResultArea.display.unsetSelected();
|
||||
this._appSearchResultArea.display.selectFirstItem();
|
||||
this._appSearchResultArea.controlBox.show();
|
||||
this._appSearchHeader.setShowTooltip(false);
|
||||
}
|
||||
|
@ -426,7 +426,11 @@ GenericDisplay.prototype = {
|
||||
|
||||
// Returns true if the display has any displayed items.
|
||||
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() {
|
||||
@ -457,6 +461,10 @@ GenericDisplay.prototype = {
|
||||
|
||||
// Displays the page specified by the pageNumber argument.
|
||||
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;
|
||||
},
|
||||
|
||||
@ -698,7 +706,6 @@ GenericDisplay.prototype = {
|
||||
*/
|
||||
_updateDisplayControl: function(resetDisplayControl) {
|
||||
if (resetDisplayControl) {
|
||||
this._selectedIndex = -1;
|
||||
this.displayControl.remove_all();
|
||||
let nPages = this._list.n_pages;
|
||||
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
|
||||
@ -754,17 +764,8 @@ GenericDisplay.prototype = {
|
||||
// Selects (e.g. highlights) a display item at the provided index,
|
||||
// updates this.selectedItemDetails actor, and emits 'selected' signal.
|
||||
_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
|
||||
if (this._selectedIndex >= 0) {
|
||||
if (this.hasSelected()) {
|
||||
this._findDisplayedByIndex(this._selectedIndex).markSelected(false);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user