-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Now search history is stored in state and can be traversed using arrow keys while focus is on search text #13237
Conversation
…he search history using key up and key down in search bar
…bh95/SearchHistory
src/search/FindBar.js
Outdated
searchHistory.splice(searchQueryIndex, 1); | ||
} else { | ||
if (searchHistory.length === maxCount) { | ||
searchHistory.splice(maxCount - 1, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't .pop()
the same thing?
src/search/FindBar.js
Outdated
@@ -333,6 +346,15 @@ define(function (require, exports, module) { | |||
// if Shift is held down). | |||
self.trigger("doFind", e.shiftKey); | |||
} | |||
currentIndex = 0; | |||
} else if (e.keyCode === KeyEvent.DOM_VK_DOWN) { | |||
currentIndex = (currentIndex - 1 + Math.min(maxCount, searchHistory.length)) % Math.min(maxCount, searchHistory.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (140 chars)
src/search/FindBar.js
Outdated
@@ -267,6 +267,7 @@ define(function (require, exports, module) { | |||
FindBar._addFindBar(this); | |||
|
|||
var $root = this._modalBar.getRoot(); | |||
var currentIndex = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rename this to historyIndex
or something little more specific
src/search/FindBar.js
Outdated
$("#find-what").val(searchHistory[currentIndex]); | ||
self.trigger("queryChange"); | ||
} else if (e.keyCode === KeyEvent.DOM_VK_UP) { | ||
currentIndex = (currentIndex + 1 + Math.min(maxCount, searchHistory.length)) % Math.min(maxCount, searchHistory.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you wrap if (e.keyCode === KeyEvent.DOM_VK_DOWN)
and if (e.keyCode === KeyEvent.DOM_VK_UP) {
codes into a function taking an argument up or down? code seems to repeat itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks good to me. We might want to add some UI at a later point of time.
@saurabh95 Great job! This is a very handy feature for developers. Keep these coming... 👍 |
This implementation doesn't have any UI as per this PR. We can have a discussion regarding its UI. There is also a trello card regarding the same with UI also https://trello.com/c/IzACddEv/344-s-find-recent-search-history .
Will have UI implementation(as per the discussion) in next PR.