JavaScript functions in InsertText commands can now receive selected text as an argument, enabling more interesting text transformation workflows:
selection child node in KDL configuration to pass selected text to JS functions// js block
export function toUppercase(selection) {
return selection.toUpperCase();
}
// kdl block
bind "Cmd Shift U" icon="text-uppercase" alias="uppercase" description="Convert selection to uppercase" {
InsertText {
callFunc "toUppercase" {
selection
}
}
}
// js block
export const toBackticks = selection => `\`${selection}\``
// kdl block
bind "Cmd U" icon="code" description="Wrap selection with backticks" {
InsertText {
callFunc "toBackticks" {
selection
}
}
}
How it might look in settings:

For completeness: backticks can be expressed without a JS block too, like so:
// kdl block
bind "Cmd U" icon="code" description="Wrap selection with backticks" {
InsertText {
string "`{{selection}}`"
}
}
Have fun optimizing your workflow!
Thank you for using Shelv!