mirror of
https://github.com/adobe/brackets.git
synced 2024-11-20 18:02:54 +01:00
Moved getInitialQuery from FindUtils to FindBar
This commit is contained in:
parent
d22c8f0e15
commit
f6992b7ee7
@ -551,6 +551,53 @@ define(function (require, exports, module) {
|
||||
this.trigger("doFind");
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets you the right query and replace text to prepopulate the Find Bar.
|
||||
* @static
|
||||
* @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
|
||||
*/
|
||||
FindBar.getInitialQuery = function (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 "";
|
||||
}
|
||||
|
||||
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 openedFindBar = FindBar._bars && _.find(FindBar._bars, function (bar) {
|
||||
return !bar.isClosed();
|
||||
});
|
||||
|
||||
if (openedFindBar) {
|
||||
query = openedFindBar.getQueryInfo().query;
|
||||
replaceText = openedFindBar.getReplaceText();
|
||||
} else if (editor) {
|
||||
query = getInitialQueryFromSelection(editor);
|
||||
}
|
||||
}
|
||||
|
||||
return {query: query, replaceText: replaceText};
|
||||
};
|
||||
|
||||
PreferencesManager.stateManager.definePreference("caseSensitive", "boolean", false);
|
||||
PreferencesManager.stateManager.definePreference("regexp", "boolean", false);
|
||||
PreferencesManager.convertPreferences(module, {"caseSensitive": "user", "regexp": "user"}, true);
|
||||
|
@ -132,7 +132,7 @@ define(function (require, exports, module) {
|
||||
|
||||
// Get initial query/replace text
|
||||
var currentEditor = EditorManager.getActiveEditor(),
|
||||
initialQuery = FindUtils.getInitialQuery(_findBar, currentEditor);
|
||||
initialQuery = FindBar.getInitialQuery(_findBar, currentEditor);
|
||||
|
||||
// Close our previous find bar, if any. (The open() of the new _findBar will
|
||||
// take care of closing any other find bar instances.)
|
||||
|
@ -610,7 +610,7 @@ define(function (require, exports, module) {
|
||||
state.searchStartPos = editor.getCursorPos(false, "start");
|
||||
|
||||
// Prepopulate the search field
|
||||
var initialQuery = FindUtils.getInitialQuery(findBar, editor);
|
||||
var initialQuery = FindBar.getInitialQuery(findBar, editor);
|
||||
|
||||
// Close our previous find bar, if any. (The open() of the new findBar will
|
||||
// take care of closing any other find bar instances.)
|
||||
|
@ -32,7 +32,6 @@ 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"),
|
||||
PreferencesManager = require("preferences/PreferencesManager"),
|
||||
EventDispatcher = require("utils/EventDispatcher"),
|
||||
@ -105,52 +104,6 @@ define(function (require, exports, module) {
|
||||
replaceWith = replaceWith.replace(/\$\$/g, "$");
|
||||
return replaceWith;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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 "";
|
||||
}
|
||||
|
||||
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 openedFindBar = FindBar._bars && _.find(FindBar._bars, function (bar) {
|
||||
return !bar.isClosed();
|
||||
});
|
||||
|
||||
if (openedFindBar) {
|
||||
query = openedFindBar.getQueryInfo().query;
|
||||
replaceText = openedFindBar.getReplaceText();
|
||||
} else if (editor) {
|
||||
query = getInitialQueryFromSelection(editor);
|
||||
}
|
||||
}
|
||||
|
||||
return {query: query, replaceText: replaceText};
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a set of replacements in a single document in memory.
|
||||
@ -570,7 +523,6 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
exports.parseDollars = parseDollars;
|
||||
exports.getInitialQuery = getInitialQuery;
|
||||
exports.hasCheckedMatches = hasCheckedMatches;
|
||||
exports.performReplacements = performReplacements;
|
||||
exports.labelForScope = labelForScope;
|
||||
|
Loading…
Reference in New Issue
Block a user