@@ -136062,8 +136062,9 @@ define("search/FindBar", function (require, exports, module) {
136062136062 let intervalId = 0,
136063136063 lastQueriedText = "",
136064136064 lastTypedText = "",
136065- lastTypedTextWasRegexp = false;
136066- const MAX_HISTORY_RESULTS = 50;
136065+ lastTypedTextWasRegexp = false,
136066+ lastClosedQuery = null;
136067+ const MAX_HISTORY_RESULTS = 25;
136067136068 const PREF_MAX_HISTORY = "maxSearchHistory";
136068136069
136069136070 const INSTANT_SEARCH_INTERVAL_MS = 50;
@@ -136640,6 +136641,12 @@ define("search/FindBar", function (require, exports, module) {
136640136641 FindBar.prototype.close = function (suppressAnimation) {
136641136642 lastQueriedText = "";
136642136643 if (this._modalBar) {
136644+ lastClosedQuery = {
136645+ query: this.$("#find-what").val() || "",
136646+ replaceText: this.getReplaceText(),
136647+ isCaseSensitive: this.$("#find-case-sensitive").is(".active"),
136648+ isRegexp: this.$("#find-regexp").is(".active")
136649+ };
136643136650 this._addElementToSearchHistory($("#find-what").val(), $("#fif-filter-input").val());
136644136651 // 1st arg = restore scroll pos; 2nd arg = no animation, since getting replaced immediately
136645136652 this._modalBar.close(true, !suppressAnimation);
@@ -136665,15 +136672,18 @@ define("search/FindBar", function (require, exports, module) {
136665136672 * @return {{query: string, caseSensitive: boolean, isRegexp: boolean}}
136666136673 */
136667136674 FindBar.prototype.getQueryInfo = function (usePlatformLineEndings = true) {
136668- let query = this.$("#find-what").val() || "";
136675+ const $findWhat = this.$("#find-what");
136676+ const findTextArea = $findWhat[0];
136677+ let query = $findWhat.val() || "";
136669136678 const lineEndings = FileUtils.sniffLineEndings(query);
136670136679 if (usePlatformLineEndings && lineEndings === FileUtils.LINE_ENDINGS_LF && brackets.platform === "win") {
136671136680 query = query.replace(/\n/g, "\r\n");
136672136681 }
136673136682 return {
136674136683 query: query,
136675136684 isCaseSensitive: this.$("#find-case-sensitive").is(".active"),
136676- isRegexp: this.$("#find-regexp").is(".active")
136685+ isRegexp: this.$("#find-regexp").is(".active"),
136686+ isQueryTextSelected: findTextArea.selectionStart !== findTextArea.selectionEnd
136677136687 };
136678136688 };
136679136689
@@ -136860,7 +136870,7 @@ define("search/FindBar", function (require, exports, module) {
136860136870 * @private
136861136871 * @static
136862136872 * @param {?FindBar} currentFindBar - The currently open Find Bar, if any.
136863- * @param {?Editor} activeEditor - The active editor, if any.
136873+ * @param {?Editor} editor - The active editor, if any.
136864136874 * @return {{query: string, replaceText: string}} An object containing the query and replacement text
136865136875 * to prepopulate the Find Bar.
136866136876 */
@@ -136881,11 +136891,31 @@ define("search/FindBar", function (require, exports, module) {
136881136891 return !bar.isClosed();
136882136892 }
136883136893 );
136884-
136885- if (openedFindBar) {
136894+ // this happens when the find in files bar is opened and we are trying to open single file search or
136895+ // vice versa. we need to detect the other findbar and determine what is the search term to use
136896+
136897+ //debugger
136898+ const currentQueryInfo = openedFindBar && openedFindBar.getQueryInfo();
136899+ if(!openedFindBar && selection){
136900+ // when no findbar is open, the selected text always takes precedence in both single and multi file
136901+ query = selection;
136902+ } else if(openedFindBar && selection && currentQueryInfo && !currentQueryInfo.isRegexp && currentQueryInfo.isQueryTextSelected) {
136903+ // we are switching between single<>multi file search without the user editing the search text in between
136904+ // while there is an active selection, the selection takes precedence.
136905+ query = selection;
136906+ replaceText = openedFindBar.getReplaceText();
136907+ } else if (openedFindBar) {
136908+ // there is no selection and we are switching between single<>multi file search, copy the
136909+ // current query from the open findbar as is
136886136910 query = openedFindBar.getQueryInfo().query;
136887136911 replaceText = openedFindBar.getReplaceText();
136912+ } else if (lastClosedQuery) {
136913+ // these is no open find bar currently and there is no selection, but there is a last saved query, so
136914+ // load the last query. this happenes on all freash search cases apart from the very first time
136915+ query = lastClosedQuery.query;
136916+ replaceText = lastClosedQuery.replaceText;
136888136917 } else if (editor) {
136918+ // the very first query after app start, nothing to restore.
136889136919 query = (!lastTypedTextWasRegexp && selection) || lastQueriedText || lastTypedText;
136890136920 }
136891136921 }
@@ -138978,6 +139008,45 @@ define("search/FindReplace", function (require, exports, module) {
138978139008 }
138979139009 }
138980139010
139011+ function _markCurrentPos(editor) {
139012+ var cm = editor._codeMirror;
139013+ const pos = editor.getCursorPos(false, "start");
139014+ cm.operation(function () {
139015+ var state = getSearchState(cm);
139016+ clearCurrentMatchHighlight(cm, state);
139017+
139018+ let curIndex = editor.indexFromPos(pos);
139019+ curIndex = curIndex >= 1 ? curIndex-- : 0;
139020+ let thisMatch = _getNextMatch(editor, false, editor.posFromIndex(curIndex));
139021+ if (thisMatch) {
139022+ let previousMatch = _getNextMatch(editor, true, thisMatch.start);
139023+ if(previousMatch){
139024+ const start = editor.indexFromPos(previousMatch.start), end = editor.indexFromPos(previousMatch.end);
139025+ if(curIndex >= start && curIndex <= end) {
139026+ thisMatch = previousMatch;
139027+ }
139028+ }
139029+ // Update match index indicators - only possible if we have resultSet saved (missing if FIND_MAX_FILE_SIZE threshold hit)
139030+ if (state.resultSet.length) {
139031+ _updateFindBarWithMatchInfo(state,
139032+ {from: thisMatch.start, to: thisMatch.end}, false);
139033+ // Update current-tickmark indicator - only if highlighting enabled (disabled if FIND_HIGHLIGHT_MAX threshold hit)
139034+ if (state.marked.length) {
139035+ ScrollTrackMarkers.markCurrent(state.matchIndex); // _updateFindBarWithMatchInfo() has updated this index
139036+ }
139037+ }
139038+
139039+ // Only mark text with "current match" highlight if search bar still open
139040+ if (findBar && !findBar.isClosed()) {
139041+ // If highlighting disabled, apply both match AND current-match styles for correct appearance
139042+ var curentMatchClassName = state.marked.length ? "searching-current-match" : "CodeMirror-searching searching-current-match";
139043+ state.markedCurrent = cm.markText(thisMatch.start, thisMatch.end,
139044+ { className: curentMatchClassName, startStyle: "searching-first", endStyle: "searching-last" });
139045+ }
139046+ }
139047+ });
139048+ }
139049+
138981139050 /**
138982139051 * Selects the next match (or prev match, if searchBackwards==true) starting from either the current position
138983139052 * (if pos unspecified) or the given position (if pos specified explicitly). The starting position
@@ -139152,11 +139221,13 @@ define("search/FindReplace", function (require, exports, module) {
139152139221 setQueryInfo(state, findBar.getQueryInfo(false));
139153139222 updateResultSet(editor);
139154139223
139155- if (state.parsedQuery) {
139224+ if(initial){
139225+ _markCurrentPos(editor);
139226+ } else if (state.parsedQuery && !initial) {
139156139227 // 3rd arg: prefer to avoid scrolling if result is anywhere within view, since in this case user
139157139228 // is in the middle of typing, not navigating explicitly; viewport jumping would be distracting.
139158139229 findNext(editor, false, true, state.searchStartPos);
139159- } else if (!initial) {
139230+ } else {
139160139231 // Blank or invalid query: just jump back to initial pos
139161139232 editor._codeMirror.setCursor(state.searchStartPos);
139162139233 }
0 commit comments