Last active
August 29, 2015 20:15
-
-
Save DiGi/40158 to your computer and use it in GitHub Desktop.
Fixed version from http://azarask.in/verbs/ + replace-all
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fixed version from http://azarask.in/verbs/ + replace-all - digi@qr.cz | |
CmdUtils.CreateCommand({ | |
name: "replace", | |
takes: {"what": noun_arb_text}, | |
modifiers: {with: noun_arb_text, in: noun_arb_text}, | |
preview: function( pblock, what, mods ) { | |
// args contains .with and .in, both of which are input objects. | |
var msg = 'Replaces "{$what}" with {$with} in {$in}.'; | |
var subs = {what: what.text, with: mods.with.text, in: mods.in.text}; | |
pblock.innerHTML = CmdUtils.renderTemplate( msg, subs ); | |
}, | |
execute: function( what, mods ) { | |
// If the scope text isn't specified, use the current selection. | |
var text = mods.in.text || CmdUtils.getTextSelection(); | |
var newText = text.replace( what.text, mods.with.text, "i"); | |
CmdUtils.setSelection( newText ); | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "replace-all", | |
takes: {"what": noun_arb_text}, | |
modifiers: {with: noun_arb_text, in: noun_arb_text}, | |
preview: function( pblock, what, mods ) { | |
// args contains .with and .in, both of which are input objects. | |
var msg = 'Replaces all "{$what}" with {$with} in {$in}.'; | |
var subs = {what: what.text, with: mods.with.text, in: mods.in.text}; | |
pblock.innerHTML = CmdUtils.renderTemplate( msg, subs ); | |
}, | |
execute: function( what, mods ) { | |
// If the scope text isn't specified, use the current selection. | |
var text = mods.in.text || CmdUtils.getTextSelection(); | |
var newText = text.replace( what.text, mods.with.text, "gi"); | |
CmdUtils.setSelection( newText ); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment