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

Keep query and replace text when switching between Replace and Replace In Files #9601

Merged
merged 4 commits into from
Oct 21, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion src/htmlContent/findreplace-bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

{{#replace}}
<div id="replace-group" {{#scope}}class="has-scope"{{/scope}}><!--
--><input type="text" id="replace-with" placeholder="{{Strings.REPLACE_PLACEHOLDER}}"/><!--
--><input type="text" id="replace-with" placeholder="{{Strings.REPLACE_PLACEHOLDER}}" value="{{initialReplaceText}}" /><!--
{{^multifile}}
--><button id="replace-yes" class="btn no-focus" tabindex="-1">{{Strings.BUTTON_REPLACE}}</button><!--
{{/multifile}}
Expand Down
1 change: 1 addition & 0 deletions src/search/FindBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ define(function (require, exports, module) {
replace: false,
queryPlaceholder: "",
initialQuery: "",
initialReplaceText: "",
scopeLabel: ""
};
this._options = _.extend(defaults, options);
Expand Down
20 changes: 16 additions & 4 deletions src/search/FindInFilesUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,26 @@ define(function (require, exports, module) {
}

// Default to searching for the current selection
var currentEditor = EditorManager.getActiveEditor(),
initialQuery = "";
var initialQuery = "",
Copy link
Contributor

Choose a reason for hiding this comment

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

Keep currentEditor declared here, even though it's not set until later because JS hoists it, anyway.

initialReplaceText = "";

if (_findBar && !_findBar.isClosed()) {
// The modalBar was already up. When creating the new modalBar, copy the
// current query instead of using the passed-in selected text.
initialQuery = _findBar.getQueryInfo().query;
} else if (currentEditor) {
initialQuery = FindUtils.getInitialQueryFromSelection(currentEditor);
initialReplaceText = _findBar.getReplaceText();
} else {
var currentEditor = EditorManager.getActiveEditor(),
openedFindbars = FindBar._bars && FindBar._bars.filter(function (findBar) {
return !findBar.isClosed();
});

if (openedFindbars && openedFindbars.length) {
initialQuery = openedFindbars[0].getQueryInfo().query;
initialReplaceText = openedFindbars[0].getReplaceText();
} else if (currentEditor) {
initialQuery = FindUtils.getInitialQueryFromSelection(currentEditor);
}
}

// Close our previous find bar, if any. (The open() of the new _findBar will
Expand All @@ -151,6 +162,7 @@ define(function (require, exports, module) {
multifile: true,
replace: showReplace,
initialQuery: initialQuery,
initialReplaceText: initialReplaceText,
queryPlaceholder: Strings.FIND_QUERY_PLACEHOLDER,
scopeLabel: FindUtils.labelForScope(scope)
});
Expand Down
16 changes: 14 additions & 2 deletions src/search/FindReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,23 @@ define(function (require, exports, module) {
state.searchStartPos = editor.getCursorPos(false, "start");

// Prepopulate the search field
var initialQuery;
var initialQuery,
initialReplaceText = "";
if (findBar) {
// Use the previous query. This can happen if the user switches from Find to Replace.
initialQuery = findBar.getQueryInfo().query;
initialReplaceText = findBar.getReplaceText();
} else {
initialQuery = FindUtils.getInitialQueryFromSelection(editor);
var openedFindbars = FindBar._bars && FindBar._bars.filter(function (findBar) {
Copy link
Contributor

Choose a reason for hiding this comment

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

findBar is already used in module scope, so change it in this inner scope to something like bar to make code easier to read.

return !findBar.isClosed();
});

if (openedFindbars && openedFindbars.length) {
initialQuery = openedFindbars[0].getQueryInfo().query;
initialReplaceText = openedFindbars[0].getReplaceText();
} else {
initialQuery = FindUtils.getInitialQueryFromSelection(editor);
}
}

// Close our previous find bar, if any. (The open() of the new findBar will
Expand All @@ -612,6 +623,7 @@ define(function (require, exports, module) {
multifile: false,
replace: replace,
initialQuery: initialQuery,
initialReplaceText: initialReplaceText,
queryPlaceholder: Strings.FIND_QUERY_PLACEHOLDER
});
findBar.open();
Expand Down