Unable to create a wrap-selection keyboard shortcut for square brackets?

Well, I am unable to create a keyboard shortcut that allows me to make auto-closing square brackets. Is this an intentional TW feature to protect from any sort of soft-locking, so to speak?

This is what I have tried so far:

"title": "¢:/core/ui/EditorToolbar/Comment",
"tags": "$:/tags/EditorToolbar",
"text": "
<$action-sendmessage
$message="tm-edit-text-operation"
$param="wrap-selection"
prefix='['
suffix=']'
/>
",
"caption": "sq. bracket Keyboard Shortcut",
"condition": "[<targetTiddler>!has[type]][<targetTiddler>]",
"shortcuts": "["

Sorry about the (technically incorrect) JSON formatting, that’s just what I figured would give the most info in the least amount of characters.

oh, and don’t mind the ¢:/, that’s just how I categorize my own system tiddlers, or my “¢ustom tiddlers”, TW sees it as just normal tiddlers, so it doesn’t seem to be any trouble.

Am I doing something incorrectly? my other shortcuts are identical to above and work fine, just not for the bracket keys (so far as I have tested, anyways.)

I’d like for a way to make self-closing brackets, and quotation marks, so any help is appreciated.

EDIT: Oo, actually bonus question (sorry)- is there a way to prevent the wrap-selection param from un-typing the characters if pressed a second time but still place the cursor between the added characters?

EDIT-2: I did also try using a modifier key along with the [ key, specifically the shortcut alt+[ but that also did not work.

A quick comment is to turn your strings into variables before use so they are not miss interpreted in the action.

In the text;

<$vars open="[" close="]">
<$action-sendmessage
$message="tm-edit-text-operation"
$param="wrap-selection"
prefix=<<open>>
suffix=<<close>>
/>
</$vars>
  • Or if that does not work in a tiddler tagged $:/tags/Macro
\define open() [
\define close() ]

Let us know how you go

unfortunately I am still unable to have this action work at the press of the [ key, or at the press of the alt key and [ key.

However, that is neat that you can use variables in such a way, I’m sure I can make good use of that in the future :smiley:

I think someone else needs to help you with the shortcuts. You must however use a modifier key such as alt/ctrl/shift and make sure you are not using an existing combination. If you have something installed that traps “[” you will also have difficulty.

I do not think we have the necessary primitive affordances to be able to create autocompletion solutions using wikitext, i.e. I don’t think any of the existing tm-edit-text-operations will give you the behaviour that you want.

However the reason your actions are not being triggered is likely because you do not have a physical [ key on your keyboard. Shortcuts depend on the keys being used rather than the character, so for instance Alt8 or the equivalent to enter a [ character on your keyboard should trigger the actions.

Hm, I’m not sure I follow. I do have a physical key for both square brackets, as I use the American QWERTY layout.

Do you need to use a modifier key like Alt, Ctrl or Enter to use the [ character?

I do not, I only need to use a modifier key when trying to create curly brackets.

I’ve been testing it and I can use all modifier and letter/number combinations but unfortunately it doesn’t seem to work with any character keys, such as , . ; ' [ ] \

This is the layout I use. (just not using an apple keyboard, so instead of a command key it is a windows key and alt instead of option)

Odd. On tiddlywiki.com, go to Keyboard Shortcuts in the Control Panel and expand any keyboard shortcut and try to modify it. Enter the [ key as the new keyboard shortcut and check what it is saved as.

I will give it a try, one moment

EDIT: odd, instead of the character it uses ‘Openbracket’ and ‘Closebracket’

sure enough that works, fasinating, thank you @saqimtiaz! I can work with this.

EDIT-2: One last question, is there a way to have the wrap-selection not undo on a second press, but still place the cursor between the prefix and suffix?

Not that I am aware of.

Hm, alrighty, welp I’ll see about cloning and modifying the wrap-selection.js tiddler to see if I can make something that works

Thank you for the help!

Maybe you could use a combination of save-selection and replace-selection edit-text operations, with a little filter magic to add the brackets ?

Fred

That could be a good idea, I’ll give that a shot when I get to TW