-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Keep query and replace text when switching between Replace and Replace In Files #9601
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ define(function (require, exports, module) { | |
MainViewManager = require("view/MainViewManager"), | ||
FileSystem = require("filesystem/FileSystem"), | ||
FileUtils = require("file/FileUtils"), | ||
FindBar = require("search/FindBar").FindBar, | ||
ProjectManager = require("project/ProjectManager"), | ||
Strings = require("strings"), | ||
StringUtils = require("utils/StringUtils"), | ||
|
@@ -71,19 +72,50 @@ define(function (require, exports, module) { | |
return replaceWith; | ||
} | ||
|
||
/* | ||
* Returns the string used to prepopulate the find bar | ||
* @param {!Editor} editor | ||
* @return {string} first line of primary selection to populate the find bar | ||
/** | ||
* Gets you the right query and replace text to prepopulate the Find Bar. | ||
* @param {?FindBar} currentFindBar The currently open Find Bar, if any | ||
* @param {?Editor} The active editor, if any | ||
* @return {query: string, replaceText: string} Query and Replace text to prepopulate the Find Bar with | ||
*/ | ||
function getInitialQueryFromSelection(editor) { | ||
var selectionText = editor.getSelectedText(); | ||
if (selectionText) { | ||
return selectionText | ||
.replace(/^\n*/, "") // Trim possible newlines at the very beginning of the selection | ||
.split("\n")[0]; | ||
function getInitialQuery(currentFindBar, editor) { | ||
var query = "", | ||
replaceText = ""; | ||
|
||
/* | ||
* Returns the string used to prepopulate the find bar | ||
* @param {!Editor} editor | ||
* @return {string} first line of primary selection to populate the find bar | ||
*/ | ||
function getInitialQueryFromSelection(editor) { | ||
var selectionText = editor.getSelectedText(); | ||
if (selectionText) { | ||
return selectionText | ||
.replace(/^\n*/, "") // Trim possible newlines at the very beginning of the selection | ||
.split("\n")[0]; | ||
} | ||
return ""; | ||
} | ||
return ""; | ||
|
||
if (currentFindBar && !currentFindBar.isClosed()) { | ||
// The modalBar was already up. When creating the new modalBar, copy the | ||
// current query instead of using the passed-in selected text. | ||
query = currentFindBar.getQueryInfo().query; | ||
replaceText = currentFindBar.getReplaceText(); | ||
} else { | ||
var openedFindbars = FindBar._bars && FindBar._bars.filter(function (bar) { | ||
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. Since you're only interested in the first non-closed bar, you should use 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. I used 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. Cool -- even better. With 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. ... and that's why I didn't use it :D |
||
return !bar.isClosed(); | ||
}); | ||
|
||
if (openedFindbars && openedFindbars.length) { | ||
query = openedFindbars[0].getQueryInfo().query; | ||
replaceText = openedFindbars[0].getReplaceText(); | ||
} else if (editor) { | ||
query = getInitialQueryFromSelection(editor); | ||
} | ||
} | ||
|
||
return {query: query, replaceText: replaceText}; | ||
} | ||
|
||
/** | ||
|
@@ -311,7 +343,7 @@ define(function (require, exports, module) { | |
} | ||
|
||
exports.parseDollars = parseDollars; | ||
exports.getInitialQueryFromSelection = getInitialQueryFromSelection; | ||
exports.getInitialQuery = getInitialQuery; | ||
exports.hasCheckedMatches = hasCheckedMatches; | ||
exports.performReplacements = performReplacements; | ||
exports.labelForScope = labelForScope; | ||
|
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.
Keep
currentEditor
declared here, even though it's not set until later because JS hoists it, anyway.