How to use tm-edit-text-operation message?

I’ve never used this message before and think the problem might be in the requirement of “surrounding editor”?

I have a stored default value and stored original value. I want to have it so that while editing in the edit-box, they can click cancel and the original value will replace all the text in the edit box.

Example code that doesn’t work, but shows how it sounds like it should work

\define cancel()
<$action-sendmessage $message="tm-edit-text-operation" $param="replace-all" text="cancelled"/>
\end

<$keyboard key="escape" actions=<<cancel>>>
<$edit-text tiddler="$:/temp/testing" tag="input" size="30"/>
</$keyboard>

Relevant documentation: https://tiddlywiki.com/#WidgetMessage%3A%20tm-edit-text-operation

I’ve put other action widgets like setfield in that same “cancel” macro, so the rest of the syntax must be okay as far as I can tell.

Less important but related question is that the <$keyboard> widget has a parameter for “message” and “parameter”, but where would I put the text value? Just as text="" too within the widget as if it was a parameter?

@stobot I am not yet well versed in the keyboard actions so may not be able to assist directly however some quick points I could not confirm from your post.

  • tm-edit-text-operation and its parameter variations are used in the text editor (you implied this)
  • These operators typically act on selected text.
  • What if your change actions copy to clipboard, from which a ctrl-v restored
    • Or even nicer pump the old content into a data tiddler and make your own in wiki clipboard tool
    • The esc key could be designed to pull from the last entry in a the in wiki clipboard
    • It would be nice to find a way to apply “tm-edit-text-operation(s)” in other ways like you are trying too but I don’t recall seeing it before.

Just so you know - being in Australia a lot happens overnight in the community so you may not see my reply for 12+ hours and I yours for 12+ hours hence my late reply and my pumping possibly useful content to you so you may proceed with you project even if I am in bed. This will mean sometimes my content is not 100% relevant but maybe. I am just trying to help and If it helps great, if not well I tried. I have received enough thanks to suggest I keep doing it.

Best wishes.

1 Like

@stobot the tm-edit-text-operation needs to be invoked from within a text editor. So in order to use it, you need to invoke it via a toolbar button or other UI component that gets transcluded into the “framed editor” that is used for the tiddler text body and has a toolbar.

Since you want to invoke your actions via the keyboard widget, you probably want to use action-setfield instead.

I do not have the opportunity at present for a more in-depth explanation of the difference between the two approaches but if you have further questions feel free to ask.

Thanks @saqimtiaz - I’ll eventually try to reverse-engineer the editTemplate to figure out what that means, but suffice to say a standard <$edit-text/> widget alone is not enough to take advantage, so I get that for now (would be cool if that could be done though)

From a <$action-setfield/> standpoint, I tried playing with that, and while the action fires and changes the content of the tiddler that the edit-text is connected to, it doesn’t reflect on the screen, which is why I started pursuing the edit-text-operation message.

For example, I would think that this code would do what I want, but you can see it changes the target tiddler, but not the <$edit-text box…

\define escape-actions() <$action-setfield $tiddler="output" $value="default"/>

<$keyboard key="escape" actions=<<escape-actions>>>
<$edit-text tiddler="output" size="50" tag="input" default="" focus="true"/>
</$keyboard>

edit-text-changes

I did find that surrounding it all with the tv-action-refresh-policy="always" variable call makes it work on a second run, but not the first one. Anyone have insight if that’s supposed to work, or some other alternative method that accomplishes the same thing?

Thanks for your thoughts @TW_Tones - in this case though the actual change in content was less the problem than having it reflect on the screen real-time, so your alternative method has merit separately, but doesn’t solve my particular use-case. I always appreciate your attempt and they have been enough to get me to the answer many times in the past :slight_smile:

The input/textarea wont refresh while it has focus, to prevent potential data loss.
But you can force it, untested code follows:

\define escape-actions()
<$action-setfield $tiddler="output" $value="default"/>
<$action-setfield $tiddler="$:/temp/myrefreshtitle" text=""/>
\end

<$keyboard key="escape" actions=<<escape-actions>>>
<$edit-text tiddler="output" size="50" tag="input" default="" focus="true" refreshTitle="$:/temp/myrefreshtitle"/>
</$keyboard>
1 Like

Worked perfectly @saqimtiaz - good tip, thanks.

Sorry for digging out this old thread but it was just what I needed: I was trying to intercept the newline in a text-Input with a KeyboardWidget to modify the content - which worked primary.
After that I was struggling, too, with showing the change in the edit-field.
Not knowing that it doesn’t refresh because of the reason you (@saqimtiaz) said.
Thank you for your solution!