Bug 322118 - Calls to view.selectedText() in the View API from Snippets plugin fail
Summary: Calls to view.selectedText() in the View API from Snippets plugin fail
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: plugin-snippets (show other bugs)
Version: 3.10.5
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Joseph Wenninger
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-08 14:44 UTC by Graham Morrison
Modified: 2014-09-23 20:45 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.1


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.