Keyboard Shortcut For Inserting Text Into Tiddler At Cursor Location

I would like to create a keyboard shortcut to insert the text (css styling):

@@margin-left:50px;@@

into any current tiddler. I have gotten as far as creating a tiddler titled $:/config/ShortcutInfo/50px-indentor, with the following description which appears under the control panel keyboard shorcuts tab:

Creates a css styling that indents all text inside the `@@` by 50px.

I also have a tiddler titled $:/config/shortcuts/50px-indentor with alt-6 in the text field. alt-6 shows up as the key binding for my 50px-indentor keyboard shorcut under the control panel keyboard shortcuts tab. I have also created a tiddler titled 50px-indentor with the tag $:/tags/KeyboardShortcut, a key field of ((50px-indentor)), and a text field of:

<$keyboard key="((50px-indentor))">
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="insert-text"
	character="@@margin-left:50px;@@"
	count="1"
/>
</$keyboard>

I have been successful with getting the shortcut to work with an alternate action widget, but I have been unsuccessful with this widget. Would someone please show me what I’m missing. The documentation on the action-sendmessage and keyboard widgets has been confusing. Screenshot of the 3 above-mentioned tiddlers below:
keyboardshorcut

Before I look at your specific case here have you tried the Editor Toolbar stamp?

  • It allows you to save pieces of text to insert into the text field.

I would look at using an editor toolbar button if I wanted to wrap a selection or some other transformation.

1 Like

The editor toolbar stamp is nice, but I would prefer using a keyboard shortcut because I use 50px indentation quite frequently and it would make my workflow much faster.

Any editor toolbar button (and other actions) can be given a keyboard short cut.

In your shoes I wold be tempted to alter your $message=“tm-edit-text-operation” to use the selection prefix and suffix form;

  • prefix @@margin-left:50px;
  • suffix @@ so you can wrap a selection in the editor if there is a selection.

There is an interactive doc at tw-com https://tiddlywiki.com/#How%20to%20create%20dynamic%20editor%20toolbar%20buttons that creates an example “bold” button. The code for new buttons like this is:

<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="wrap-selection"
	prefix="@@margin-left:50px; "
	suffix="@@"
/>

So you have to define the prefix and suffix and the button is done. – There is a second button, that will create the keyboard shortcut.

I personally would not use hardcoded styles, because they will need to be changed individually, if you ever want to change them.

I would go for a class definition, which can be changed globally. eg:

<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="wrap-selection"
	prefix="@@.my-indent "
	suffix="@@"
/>

Create a stylesheet tiddler tagged: $:/tags/Stylesheet tiddler with

.i,
.my-indent {
  margin-left: 8em;
}

I also would make it much less to type. eg: @@.i my indented text ..., which needs an adjusted button text and the style definition from above, which accespts both “shortcuts”

have fun!
mario

2 Likes

if you really want to insert the text into the tiddler directly you might want to look at the autocomplete plugin

e.g.

http://makiaea.org/00045/20230414makiaea.html#auto%20complete

and

http://makiaea.org/00045/20230414makiaea.html#auto%20complete

as an example of how i use it

e.g. zdf inserts today’s date