Commit a8b4c0f4 authored by Beluga Whale's avatar Beluga Whale Committed by Thomas Friedrichsmeier
Browse files

Kate Snippets: add examples for working with selections

Based on what Thomas Friedrichsmeier shared in
parent 09bb868a
Pipeline #210048 passed with stage
in 11 minutes and 14 seconds
......@@ -3440,6 +3440,25 @@ documentation for more information.</para>
functions are being evaluated. E.g., if a function retrieves the text on the
line where the snippet is being inserted, that text will also contain
<para>As an example of working with selections using the scripting API, a simple way
to wrap selected text inside tags is this snippet:
<para>The following example invokes a script that inserts a default text in case
there is no selection. Snippet:</para>
<userinput>${rangeCommand("&lt;strong&gt;%%1&lt;/strong&gt;", "Bold")}</userinput></para>
function rangeCommand(command, def) {
if (view.selectedText().length > 0) {
return command.replace("%%1", view.selectedText());
} else {
return command.replace("%%1", def);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment