Bug 322118

Summary: Calls to view.selectedText() in the View API from Snippets plugin fail
Product: [Applications] kate Reporter: Graham Morrison <acquirement>
Component: plugin-snippetsAssignee: Joseph Wenninger <jowenn>
Status: RESOLVED FIXED    
Severity: normal CC: athanare, mail, pascal+kde
Priority: NOR    
Version: 3.10.5   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In: 5.1

Description Graham Morrison 2013-07-08 14:44:42 UTC
As outlined here:
http://docs.kde.org/stable/en/applications/kate/advanced-editing-tools-scripting.html

When writing a script to accompany a Snippet, calls to functions in the View API don't appear to work. Specifically, no string is returned from view.selectedText().

Reproducible: Always

Steps to Reproduce:
1. With Snippets plugin installed, create and name a new Snippet.
2. Enter:

${fn`getSelectedText`}

as the text in the Snippet tab.
3. Enter:

function getSelectedText() {
return view.selectedText();
}

as the text in the Scripts tab.
4. Apply the changes.
5. Select some text and run the Snippet.
Actual Results:  
Nothing. Seems to return null.

Expected Results:  
The text selected in the main view should be returned.

This function used to be provided within Snippets by the ${selection} keyword, but this no longer functions either. It's important for writing Snippets that surround the selected text with HTML elements, for example.
Comment 1 Pascal Niklaus 2013-08-29 11:44:49 UTC
I can confirm this behaviour.

inserting e.g. %{date} works, but %{selection} does not work.

This behaviour is critical since one often wants to write snippets that "surround" an existing block of text.
Comment 2 Sven Brauch 2014-09-23 20:45:04 UTC
Fixed in 5 with changes to the snippets engine. Use ${selection()} to get the selected text.