| Summary: | Kate Snippets: not clear how to work with selected text | ||
|---|---|---|---|
| Product: | [Applications] kate | Reporter: | Buovjaga <ilmari.lauhakangas> |
| Component: | plugin-snippets | Assignee: | Buovjaga <ilmari.lauhakangas> |
| Status: | RESOLVED FIXED | ||
| Severity: | minor | CC: | thomas.friedrichsmeier |
| Priority: | NOR | ||
| Version First Reported In: | 22.04.3 | ||
| Target Milestone: | --- | ||
| Platform: | Other | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
|
Description
Buovjaga
2022-07-18 06:09:46 UTC
Thomas: excuse me for adding you into the Cc, but I noticed your recent commit to Kate Snippets docs: https://invent.kde.org/utilities/kate/-/commit/bbdb00c136290021d642b6d9b20c0e04a8ecc9bf Maybe you have some insight on this problem. In RKWard we use the following in the snippet tab (example):
${rangeCommand("**%%1**", "Bold")}
where rangeCommand is defined as (in the scripts tab):
function rangeCommand(command, def) {
if (view.selectedText().length > 0) {
return command.replace("%%1", view.selectedText());
} else {
return command.replace("%%1", def);
}
}
This puts the selected text inside "**" markup, or inserts "**Bold**", in case nothing is selected. That took quite some experimenting to figure out, indeed....
But in fact, if you do not care about adding a default value, in case there is no selection, you can simply write (snippet tab):
<translate>${view.selectedText()}</translate>
Would you like to create a merge request adding some illustrative examples?
(In reply to Thomas Friedrichsmeier from comment #3) > But in fact, if you do not care about adding a default value, in case there > is no selection, you can simply write (snippet tab): > > <translate>${view.selectedText()}</translate> > > Would you like to create a merge request adding some illustrative examples? Thanks a lot for these! Yes, I will look into creating a merge request for the docs. |