-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Populate the replace input with the currently selected text #1962
Changes from all 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 |
---|---|---|
|
@@ -184,9 +184,14 @@ define(function (require, exports, module) { | |
findFirst(getDialogTextField().attr("value")); | ||
}); | ||
} | ||
|
||
function getCurrentEditorSelectedText() { | ||
var currentEditor = EditorManager.getFocusedEditor(); | ||
return (currentEditor && currentEditor.getSelectedText()) || ""; | ||
} | ||
|
||
var replaceQueryDialog = Strings.CMD_REPLACE + | ||
': <input type="text" style="width: 10em"/> <span style="color: #888">(' + | ||
': <input type="text" style="width: 10em" value="{{SELECTION}}"/> <span style="color: #888">(' + | ||
Strings.SEARCH_REGEXP_INFO + ')</span>'; | ||
var replacementQueryDialog = Strings.WITH + | ||
': <input type="text" style="width: 10em"/>'; | ||
|
@@ -198,7 +203,7 @@ define(function (require, exports, module) { | |
'</button> <button' + style + '>' + Strings.BUTTON_STOP + '</button>'; | ||
|
||
function replace(cm, all) { | ||
dialog(cm, replaceQueryDialog, Strings.CMD_REPLACE, function (query) { | ||
dialog(cm, replaceQueryDialog.replace("{{SELECTION}}", getCurrentEditorSelectedText()), Strings.CMD_REPLACE, function (query) { | ||
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. This doesn't do any escaping, so it could break the HTML if there are quotes/etc. in the string. Why not do it the same way as _launchFind()? That should work just as well for the Replace dialog. And since _replace() only does anything when there is an Editor available, I think you could ditch getCurrentEditorSelectedText() and follow _launchFind()'s example there too -- i.e. simpler logic for getting the initial string. 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. Oh I see... didn't notice that... I'm closing this pull request then and will submit a new one following your directions soon |
||
if (!query) { | ||
return; | ||
} | ||
|
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.
This is now used in
QuickOpen
andFindInFiles
(sort of) other than here. Maybe it would be worth refactoring at some point...