This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0469c0c
Now search history is stored in preferences and user can go through t…
saurabh95 84094f3
Fixed a minor issue
saurabh95 a70549e
Merge branch 'master' of https://github.com/adobe/brackets into saura…
saurabh95 b99b4dd
Addressed review comments and also added tests
saurabh95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,6 +267,7 @@ define(function (require, exports, module) { | |
FindBar._addFindBar(this); | ||
|
||
var $root = this._modalBar.getRoot(); | ||
var currentIndex = 0; | ||
$root | ||
.on("input", "#find-what", function () { | ||
self.trigger("queryChange"); | ||
|
@@ -310,9 +311,21 @@ define(function (require, exports, module) { | |
if (intervalId === 0) { | ||
intervalId = window.setInterval(executeSearchIfNeeded, 50); | ||
} | ||
var searchHistory = PreferencesManager.getViewState("searchHistory"); | ||
var maxCount = PreferencesManager.get("maxSearchHistory"); | ||
if (e.keyCode === KeyEvent.DOM_VK_RETURN) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
var searchQueryIndex = searchHistory.indexOf($('#find-what').val()); | ||
if (searchQueryIndex !== -1) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. isn't |
||
} | ||
} | ||
searchHistory.unshift($('#find-what').val()); | ||
PreferencesManager.setViewState("searchHistory", searchHistory); | ||
lastQueriedText = self.getQueryInfo().query; | ||
if (self._options.multifile) { | ||
if ($(e.target).is("#find-what")) { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. line too long (140 chars) |
||
$("#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 commentThe reason will be displayed to describe this comment to others. Learn more. can you wrap |
||
$("#find-what").val(searchHistory[currentIndex]); | ||
self.trigger("queryChange"); | ||
} | ||
}); | ||
|
||
|
@@ -616,6 +638,10 @@ define(function (require, exports, module) { | |
|
||
PreferencesManager.stateManager.definePreference("caseSensitive", "boolean", false); | ||
PreferencesManager.stateManager.definePreference("regexp", "boolean", false); | ||
PreferencesManager.stateManager.definePreference("searchHistory", "array", []); | ||
PreferencesManager.definePreference("maxSearchHistory", "number", 10, { | ||
description: Strings.FIND_HISTORY_MAX_COUNT | ||
}); | ||
|
||
exports.FindBar = FindBar; | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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