Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Issue #11261: keep the search bar open #11996

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8c668bc
It fixes issue #11261 by preventing the search bar from closing as a…
Sep 12, 2015
a120c12
Commented out unnecessary code around line 256
Sep 12, 2015
53f0427
[issue#11261] * Added in a menu option to allow find bar to stay open…
pldilley Dec 9, 2015
c2cdc65
[issue#11261] Code clean up of initial mistakes of the previous commit
pldilley Dec 9, 2015
ea69c5a
[issue#11261] Strange issue with spacing in src/nls/fr/strings.js...
pldilley Dec 9, 2015
a57debb
[issue#11261] Strange issue with spacing in src/nls/fr/strings.js...
pldilley Dec 9, 2015
e44b07e
Merge remote-tracking branch 'upstream/master' into issue#11261
pldilley Dec 9, 2015
20ad291
[issue#11261] Further merge conflict resolution and clean up
pldilley Dec 9, 2015
4637646
[issue#11261] Fix to branch and to testing
pldilley Dec 12, 2015
283ceb8
Merge branch 'master' of https://github.com/adobe/brackets into issue…
pldilley Dec 12, 2015
923240b
[issue#11261] Fixes for incorrect regexp processing
pldilley Dec 12, 2015
9651160
[issue#11261] Why does JSLint keep changing its own file
pldilley Dec 12, 2015
2b57f0b
[issue#11261] Not sure about the french one, let's exclude it for now…
pldilley Dec 12, 2015
949bd10
[issue#11261] Test left test file with change...
pldilley Dec 12, 2015
ab1a454
Merge branch 'master' of https://github.com/adobe/brackets into issue…
Jan 2, 2016
8981389
[issue #11261] Minor fixes as per conversation of pull request
Jan 2, 2016
1fa7c2e
Merge branch 'master' of https://github.com/adobe/brackets into issue…
pldilley Jan 14, 2016
277d241
[Issue #11261] Fixes mainly to the regular expression side of things
pldilley Jan 14, 2016
a9c8296
[Issue #11261] Revert accidental change in JSLint
pldilley Jan 14, 2016
dee88bf
[issue #11261] Remove loosy TODO and wording consistency change
pldilley Jan 14, 2016
33fbd59
[Issue #11261] Remove Find Next on 'Find' option (we already have Fin…
pldilley Jan 14, 2016
76c822d
[Issue #11261] (Retry the Travis CI build)
pldilley Jan 14, 2016
d85e888
Merge branch 'master' of https://github.com/adobe/brackets into issue…
pldilley Apr 29, 2016
26ba957
Totally forgot to actually save the merge conflict resolution. Here i…
pldilley Apr 29, 2016
dc8890f
Merge branch 'master' into issue#11261
pldilley Jan 18, 2018
4df9aab
Merged master incorrectly - fix bad merge
pldilley Jan 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ define(function (require, exports, module) {
exports.TOGGLE_LINE_NUMBERS = "view.toggleLineNumbers"; // EditorOptionHandlers.js _getToggler()
exports.TOGGLE_ACTIVE_LINE = "view.toggleActiveLine"; // EditorOptionHandlers.js _getToggler()
exports.TOGGLE_WORD_WRAP = "view.toggleWordWrap"; // EditorOptionHandlers.js _getToggler()
exports.TOGGLE_SEARCH_AUTOHIDE = "view.toggleSearchAutoHide"; // EditorOptionHandlers.js _getToggler() // TODO REMOVE_toggleSearcjAutoHide()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the // TODO comment refer to?


exports.CMD_OPEN = "cmd.open";
exports.CMD_ADD_TO_WORKINGSET_AND_OPEN = "cmd.addToWorkingSetAndOpen"; // DocumentCommandHandlers.js handleOpenDocumentInNewPane()
Expand Down
1 change: 1 addition & 0 deletions src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ define(function (require, exports, module) {
menu.addMenuItem(Commands.CMD_SPLITVIEW_HORIZONTAL);
menu.addMenuDivider();
menu.addMenuItem(Commands.VIEW_HIDE_SIDEBAR);
menu.addMenuItem(Commands.TOGGLE_SEARCH_AUTOHIDE);
menu.addMenuDivider();
menu.addMenuItem(Commands.VIEW_INCREASE_FONT_SIZE);
menu.addMenuItem(Commands.VIEW_DECREASE_FONT_SIZE);
Expand Down
6 changes: 5 additions & 1 deletion src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ define(function (require, exports, module) {
TAB_SIZE = "tabSize",
UPPERCASE_COLORS = "uppercaseColors",
USE_TAB_CHAR = "useTabChar",
WORD_WRAP = "wordWrap";
WORD_WRAP = "wordWrap",
AUTO_HIDE_SEARCH = "autoHideSearch";

var cmOptions = {};

Expand Down Expand Up @@ -207,6 +208,9 @@ define(function (require, exports, module) {
PreferencesManager.definePreference(WORD_WRAP, "boolean", true, {
description: Strings.DESCRIPTION_WORD_WRAP
});
PreferencesManager.definePreference(AUTO_HIDE_SEARCH, "boolean", true, {
description: Strings.DESCRIPTION_SEARCH_AUTOHIDE
});

var editorOptions = Object.keys(cmOptions);

Expand Down
5 changes: 4 additions & 1 deletion src/editor/EditorOptionHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ define(function (require, exports, module) {
var SHOW_LINE_NUMBERS = "showLineNumbers",
STYLE_ACTIVE_LINE = "styleActiveLine",
WORD_WRAP = "wordWrap",
CLOSE_BRACKETS = "closeBrackets";
CLOSE_BRACKETS = "closeBrackets",
AUTO_HIDE_SEARCH = "autoHideSearch";

/**
* @private
Expand All @@ -51,6 +52,7 @@ define(function (require, exports, module) {
_optionMapping[STYLE_ACTIVE_LINE] = Commands.TOGGLE_ACTIVE_LINE;
_optionMapping[WORD_WRAP] = Commands.TOGGLE_WORD_WRAP;
_optionMapping[CLOSE_BRACKETS] = Commands.TOGGLE_CLOSE_BRACKETS;
_optionMapping[AUTO_HIDE_SEARCH] = Commands.TOGGLE_SEARCH_AUTOHIDE;

/**
* @private
Expand Down Expand Up @@ -100,6 +102,7 @@ define(function (require, exports, module) {
CommandManager.register(Strings.CMD_TOGGLE_ACTIVE_LINE, Commands.TOGGLE_ACTIVE_LINE, _getToggler(STYLE_ACTIVE_LINE));
CommandManager.register(Strings.CMD_TOGGLE_WORD_WRAP, Commands.TOGGLE_WORD_WRAP, _getToggler(WORD_WRAP));
CommandManager.register(Strings.CMD_TOGGLE_CLOSE_BRACKETS, Commands.TOGGLE_CLOSE_BRACKETS, _getToggler(CLOSE_BRACKETS));
CommandManager.register(Strings.CMD_TOGGLE_SEARCH_AUTOHIDE, Commands.TOGGLE_SEARCH_AUTOHIDE, _getToggler(AUTO_HIDE_SEARCH));

AppInit.htmlReady(_init);
});
2 changes: 2 additions & 0 deletions src/htmlContent/findreplace-bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@
<div class="indexing-message">{{Strings.FIND_IN_FILES_INDEXING}}</div>
</div>
{{/multifile}}

<a href="#" class="close">&times;</a>
2 changes: 2 additions & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ define({
"CMD_WORKINGSET_SORT_BY_TYPE" : "Sort by Type",
"CMD_WORKING_SORT_TOGGLE_AUTO" : "Automatic Sort",
"CMD_THEMES" : "Themes\u2026",
"CMD_TOGGLE_SEARCH_AUTOHIDE" : "Automatically close search",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should most likely be consistent with #L763 (DESCRIPTION_SEARCH_AUTOHIDE) (Hide/close, search / search bar)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to change the description, since the action appears as a 'close' to the user (the search has an 'x' on it)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


// Navigate menu commands
"NAVIGATE_MENU" : "Navigate",
Expand Down Expand Up @@ -759,6 +760,7 @@ define({
"DESCRIPTION_USE_TAB_CHAR" : "true to use tabs instead of spaces",
"DESCRIPTION_UPPERCASE_COLORS" : "true to generate uppercase hex colors in Inline Color Editor",
"DESCRIPTION_WORD_WRAP" : "Wrap lines that exceed the viewport width",
"DESCRIPTION_SEARCH_AUTOHIDE" : "Hide the search bar as soon as the editor is focused",
"DESCRIPTION_DETECTED_EXCLUSIONS" : "A list of files that have been detected to cause Tern to run out of control",
"DESCRIPTION_INFERENCE_TIMEOUT" : "The amount of time after which Tern will time out when trying to understand files",
"DESCRIPTION_SHOW_ERRORS_IN_STATUS_BAR" : "true to show errors in status bar",
Expand Down
31 changes: 29 additions & 2 deletions src/search/FindBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,28 @@ define(function (require, exports, module) {
var templateVars = _.clone(this._options);
templateVars.Strings = Strings;
templateVars.replaceAllLabel = (templateVars.multifile ? Strings.BUTTON_REPLACE_ALL_IN_FILES : Strings.BUTTON_REPLACE_ALL);

this._modalBar = new ModalBar(
Mustache.render(_searchBarTemplate, templateVars),
!!PreferencesManager.get('autoHideSearch')
); // 2nd arg = auto-close on Esc/blur
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment and move one line up


this._modalBar = new ModalBar(Mustache.render(_searchBarTemplate, templateVars), true); // 2nd arg = auto-close on Esc/blur
// Done this way because ModalBar.js seems to react underiably when
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreliably spelt in an unreliable way.

// modifying it to handle the escape key - the findbar wasn't getting
// closed as it should, instead persisting in the background
function _handleKeydown(e) {
if (e.keyCode === KeyEvent.DOM_VK_ESCAPE) {
e.stopPropagation();
e.preventDefault();
self.close();
}
}
window.document.body.addEventListener("keydown", _handleKeydown, true);

// When the ModalBar closes, clean ourselves up.
this._modalBar.on("close", function (event) {
window.document.body.removeEventListener("keydown", _handleKeydown, true);

// Hide error popup, since it hangs down low enough to make the slide-out look awkward
self.showError(null);
self._modalBar = null;
Expand Down Expand Up @@ -293,8 +310,11 @@ define(function (require, exports, module) {
return;
}
currentTime = new Date().getTime();
if (lastTypedTime && (currentTime - lastTypedTime >= 100) && self.getQueryInfo().query !== lastQueriedText &&

if (lastTypedTime && (currentTime - lastTypedTime >= 100) &&
self.getQueryInfo().query !== lastQueriedText &&
!FindUtils.isNodeSearchInProgress()) {

// init Search
if (self._options.multifile) {
if ($(e.target).is("#find-what")) {
Expand Down Expand Up @@ -334,6 +354,9 @@ define(function (require, exports, module) {
self.trigger("doFind", e.shiftKey);
}
}
})
.on("click", ".close", function () {
self.close();
});

if (!this._options.multifile) {
Expand Down Expand Up @@ -608,6 +631,10 @@ define(function (require, exports, module) {
}
}

if (editor) {
query = getInitialQueryFromSelection(editor);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems pointless and buggy

}

return {query: query, replaceText: replaceText};
};

Expand Down
3 changes: 2 additions & 1 deletion src/search/FindInFilesUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ define(function (require, exports, module) {
var showMessage = false;
_findBar.enable(true);
if (zeroFilesToken === FindInFiles.ZERO_FILES_TO_SEARCH) {
_findBar.showError(StringUtils.format(Strings.FIND_IN_FILES_ZERO_FILES, FindUtils.labelForScope(FindInFiles.searchModel.scope)), true);
_findBar.showError(StringUtils.format(Strings.FIND_IN_FILES_ZERO_FILES,
FindUtils.labelForScope(FindInFiles.searchModel.scope)), true);
} else {
showMessage = true;
}
Expand Down
48 changes: 45 additions & 3 deletions src/search/FindReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ define(function (require, exports, module) {
// Blank or invalid query: just jump back to initial pos
editor._codeMirror.setCursor(state.searchStartPos);
}

editor.lastParsedQuery = state.parsedQuery;
}


Expand All @@ -612,6 +614,10 @@ define(function (require, exports, module) {
// Prepopulate the search field
var initialQuery = FindBar.getInitialQuery(findBar, editor);

if (initialQuery.query === "" && editor.lastParsedQuery !== "") {
initialQuery.query = editor.lastParsedQuery;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not working well with regular expression. Further manual testing and a new test case are needed

}

// Close our previous find bar, if any. (The open() of the new findBar will
// take care of closing any other find bar instances.)
if (findBar) {
Expand All @@ -636,6 +642,7 @@ define(function (require, exports, module) {
findNext(editor, searchBackwards);
})
.on("close.FindReplace", function (e) {
editor.lastParsedQuery = state.parsedQuery;
// Clear highlights but leave search state in place so Find Next/Previous work after closing
clearHighlights(cm, state);

Expand All @@ -655,12 +662,12 @@ define(function (require, exports, module) {
*/
function doSearch(editor, searchBackwards) {
var state = getSearchState(editor._codeMirror);

if (state.parsedQuery) {
findNext(editor, searchBackwards);
return;
} else {
openSearchBar(editor, false);
}

openSearchBar(editor, false);
}


Expand Down Expand Up @@ -695,6 +702,8 @@ define(function (require, exports, module) {
findBar.close();
}
}

editor.lastEditorSearchPosStr = ""; // Positions have shifted, so we abort the auto-next on findbar launch
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer relevant - remove.

}

function replace(editor) {
Expand All @@ -717,10 +726,43 @@ define(function (require, exports, module) {

function _launchFind() {
var editor = EditorManager.getActiveEditor();

if (editor) {
// Make note of the original query details
var state = getSearchState(editor._codeMirror),
qry = (findBar && state && state.parsedQuery) || "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick: this variable could be just query

idx = state && state.matchIndex;

// Create a new instance of the search bar UI
clearSearch(editor._codeMirror);
doSearch(editor, false);
_findNextIfSameSearch(qry, idx, getSearchState(editor._codeMirror));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better as a method that simply returns a boolean, and then the findNext should be executed within _launchFind. This will make the private function more reusable and make the code easier to follow.

}
}

function _findNextIfSameSearch(originalQuery, originalIdx, state) {
// Process the new query and prep the original and new for comparing
var newIdx, newQuery;

if (findBar && state && state.queryInfo && state.searchStartPos) {
newQuery = state.parsedQuery || "";
newIdx = state.matchIndex;

if (!state.queryInfo.isCaseSensitive) {
originalQuery = typeof originalQuery === "string"
? originalQuery.toLowerCase()
: originalQuery;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Over complicated if's


newQuery = typeof newQuery === "string"
? newQuery.toLowerCase()
: newQuery;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

}
}

// If the original and new query are the same, go to the next
if (originalQuery && newQuery && originalQuery === newQuery &&
originalIdx === newIdx) {
_findNext();
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/styles/brackets.less
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,15 @@ a, img {
margin-left: 0px;
border-radius: 0;
}

.close {
position: absolute;
right: 10px;

// vertically centers close button
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not helpful

top: 50%;
margin-top: -8px;
}
}

// File exclusion filter (used only in Find in Files search bar, for now)
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/ModalBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ define(function (require, exports, module) {
};

exports.ModalBar = ModalBar;
});
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure there is a new line at the end of the file

6 changes: 3 additions & 3 deletions test/spec/FindReplace-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ define(function (require, exports, module) {
});
});

it("shouldn't Find Next after search bar reopened", function () {
it("should Find Next after search bar reopened", function () {
runs(function () {
myEditor.setCursorPos(0, 0);

Expand All @@ -763,10 +763,10 @@ define(function (require, exports, module) {
twCommandManager.execute(Commands.CMD_FIND);

expectSearchBarOpen();
expect(myEditor).toHaveCursorPosition(0, 0);
expect(myEditor).toHaveCursorPosition(8, 8, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests fails for me with expected the cursor to be at (8, 8) but it actually was at (2, 8) and more than one character was selected, hmm.


twCommandManager.execute(Commands.CMD_FIND_NEXT);
expect(myEditor).toHaveCursorPosition(0, 0);
expect(myEditor).toHaveCursorPosition(8, 8, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar error with this one: expected the cursor to be at (8, 8) but it actually was at (2, 31) and more than one character was selected, hmm.

});
});

Expand Down
4 changes: 2 additions & 2 deletions test/spec/SpecRunnerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ define(function (require, exports, module) {
/**
* Expects the given editor's selection to be a cursor at the given position (no range selected)
*/
toHaveCursorPosition: function (line, ch) {
toHaveCursorPosition: function (line, ch, ignoreSelection) {
var editor = this.actual;
var selection = editor.getSelection();
var notString = this.isNot ? "not " : "";
Expand All @@ -1342,7 +1342,7 @@ define(function (require, exports, module) {

// when adding the not operator, it's confusing to check both the size of the
// selection and the position. We just check the position in that case.
if (this.isNot) {
if (this.isNot || ignoreSelection) {
return positionsMatch;
} else {
return !selectionMoreThanOneCharacter && positionsMatch;
Expand Down