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

Populate the replace input with the currently selected text #1962

Closed
wants to merge 1 commit into from
Closed

Populate the replace input with the currently selected text #1962

wants to merge 1 commit into from

Conversation

jbalsas
Copy link
Contributor

@jbalsas jbalsas commented Oct 26, 2012

Currently, the actions "Find", "Find in Files", "Quick Open" and "Go to Definition" populate their input text with the currently selected text which doesn't happen for the "Replace" action.

I don't know if this is intentional. If not, this fixes it and populates the initial replace input with the current selection.


function getCurrentEditorSelectedText() {
var currentEditor = EditorManager.getFocusedEditor();
return (currentEditor && currentEditor.getSelectedText()) || "";
Copy link
Contributor Author

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 and FindInFiles (sort of) other than here. Maybe it would be worth refactoring at some point...

@couzteau
Copy link
Member

Have been missing this functionality badly

@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants