https://bugs.kde.org/show_bug.cgi?id=456846

            Bug ID: 456846
           Summary: Kate Snippets: not clear how to work with selected
                    text
           Product: kate
           Version: 22.04.3
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: minor
          Priority: NOR
         Component: plugin-snippets
          Assignee: kwrite-bugs-n...@kde.org
          Reporter: ilmari.lauhakan...@libreoffice.org
  Target Milestone: ---

The docs for Snippets could use some love:
https://docs.kde.org/trunk5/en/kate/kate/kate-application-plugin-snippets.html

I am looking for a way to wrap the selected text in tags, for example to help
with MediaWiki Translate extension. Searching all over the web, I found many
others looking for the same information.

There is an old blog post with relevant discussion in the comments:
https://milianw.de/blog/snippets-in-kdevelop-kate.html

It is said that at some point this used to work:

<strong>%{selection}</strong>

There is a function in the view API view.selectedText() but it does not seem to
be applying or maybe I am missing something.

https://docs.kde.org/trunk5/en/kate/katepart/dev-scripting.html#dev-scripting-api

Given this in the Snippet tab

<translate>${text}</translate>

and in the Scripts tab

text = view.selectedText();

the variable will be simply be replaced by "text".

I also tried with editor.clipboardText() but the result was still "text", which
I don't understand at all.

If I use the percentage sign instead of dollar sign, like %{text}, the result
will just be %{text}.

I found this doc from 2010 that explains the difference between $ and %
variables: https://kate-editor.org/2010/02/03/snippets-in-kdevelop-kate/

"snippet gets inserted (properly indented) and potential placeholders/variables
get expanded. A variable is something like %{date} or ${email}. Also take a
look at the API documentation.
variables that get inserted via “${…}” will be “selectable”, meaning you can
jump from one var to the other by hitting TAB / Shift TAB
the %{…} vars will only get expanded and inserted, without getting selectable."

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to