Option to stop {clipboard} from adding spaces on either side

I have a simple series of snippets that allow me to copy to the clipboard text and then I use the snippet to replace that text in place with the copied text inserted.

For instance, one of my snippets is ..

<%= rule_link('{clipboard}') %>

So, for instance if I have 16.2 in my text .. I highlight and copy "16.2" into my clipboard and then while still highlighted, I type my phrase to execute the snip.

Unfortunately, when it replaces it, there is a space on either side of the clipboard text ..

<%= rule_link(' 16.2 ') %> instead of <%= rule_link('16.2') %>

Is there a way to prevent the spaces?

PS: "trim=yes" option does not seem to fix this issue. <%= rule_link('{clipboard: trim=yes}') %>

PS PS: Is there a way of, instead of using "clipboard", to select/use the currently selected-highlighted-text instead? This would save the step of copying into clipboard.

You can implement this with a formula using the trim() function. For example:

<%= rule_link('{=trim({clipboard})}') %>

Now any whitespace around the copied text command will be trimmed off.

Here is more information about formulas:

Also, it's an interesting idea about using the currently highlighted text. That's not possible now, but maybe the {site} command could be extended to support it.

2 Likes

Thanks Scott .. that worked. Was the trim variable to the clipboard also supposed to do the same thing and just not work, or is that designed to do something different?

The trim attribute available on all commands including the {clipboard} command trims whitespace around the command, but not within the command itself.

It's primarily useful for getting rid of whitespace around things like {if} and {endif} where you might want to include spacing and formatting in your snippet source for readability, but you don't want it to be in the output.

Let me know if this helps!

1 Like