An Editor Toolbar Button to Store a Selection to Another Specified Tiddler

References

Using the above references, adding a new toolbar button to editor is an easy task! but I cannot find an easy solution for below operation:

How to add an editor button to:

  1. add the selection into another tiddler (similar to excise but always a preset title is used to store the selection)
  2. if nothing selected ignore the operation / or button is deactivated

Is there a variable refers to selection?

Hi Mohammad,

If this is in reference to my comment yesterday about user-proofing, it looks like an interesting approach. I will be eager to see what you come up with.

Another approach to consider, since the weakness is not with your plugin but with the user’s memory, might be just to have a reminder in EditTemplate with a link to your index.

Hi Dave,
Yes, I am thinking how easily add words to index like LaTex!

I have implemented something similar in this piece of code.

@oflg - thank you for sharing!
It is a JS code and I have no JS knowledge, how can I use it?

The code does require javascript.

This tm-edit-text-operation WidgetMessage maybe useful.

1 Like

@Mohammad I cant find the Topic where I was inspired to to create two select and sort text editor tool bar buttons attached;

text-sorter.json (3.7 KB)

Drop on tiddlywiki.com to test.

  • It is not ready for publishing as you have to undo ctrl-z after you first attempt, and do it a second time.

Inside $:/PSaT/text-sorter/down you will see;

<$action-sendmessage
$message="tm-edit-text-operation"
$param="save-selection"
tiddler="$:/temp/selection"
/>
<$let
   new-line={{{ [charcode[13],[10]] }}}
   sorted={{{ [{$:/temp/selection}splitregexp[\n]sort[]join<new-line>] }}}
>
<$action-sendmessage
    $message="tm-edit-text-operation"
    $param="replace-selection"
    text=<<sorted>>
/>
</$let>

You can see the selection gets saved to tiddler="$:/temp/selection" in the first action.

In effect the various $message=“tm-edit-text-operation” actions have access to the selection in the editor, thus you make use of https://tiddlywiki.com/#WidgetMessage%3A%20tm-edit-text-operation in this case perhaps only save-selection excise are relevant.

However as you can see from the above example any wiki text, macros, tiddler references and actions can be used inside a editor toolbar button.

To provide a button that allows selection from a list look at the stamp or more drop downs.

If I could find the post where I responded with this I raised the possibility of handling clipboards and other methods from the Editor Toolbar.

1 Like

Thank you @TW_Tones that is what I want. I will share my solution here then!

1 Like

We tried this in fishing plugin, and found it impossible to do so without JS. But that JS code is basically copy from the tw core’s code, is pretty simple.

Thanks @TW_Tones for this code ! I wil use it back for sure ! :slightly_smiling_face:

Is there a reason why you split text delimited by \n but you join it back with charcode[13],[10] which is \r\n ?

When we produce a single file wiki we deliberately strip out the CR \r character because it saves a lot of file size and it isn’t needed. Even most windows editors are able to deal with it now.

I don’t see a reason, why it should be added.

1 Like

The answer is because I got it wrong, charcode[10] would be enough.

The error came from decades of moving between windows text files and linux and mainframe files.

Post Script: Tiddlywiki.com also gives the example of charcode[13],[10] so no wonder I used it.

Ref: An Editor Toolbar Button to Insert User Signature with Timestamp - Tips & Tricks - Talk TW (tiddlywiki.org)

With help of great friends here, I was able to answer the original question in this thread!

FACTS

  • The content of action tiddler can be any kind of action widgets
  • You have to use tm-edit-text-operation to access to selection

Solution

  • Create an action tiddler with below text and fields
\define myTargetTid() Target
\define tempTid() $:/temp/append-button/selection

<$action-sendmessage
 $message="tm-edit-text-operation"
 $param="save-selection"
 tiddler=<<tempTid>>
/>

<$vars linebreak="
">
<$action-setfield $tiddler=<<myTargetTid>> text={{{ [<myTargetTid>get[text]] [<tempTid>get[text]]  +[join<linebreak>] }}}/>
</$vars>

|tags: |$:/tags/EditorToolbar|
|caption: |append selection |
|condition: | [<targetTiddler>] |
|description: |Append selection to target tiddler|
|icon: |$:/core/images/new-button |

  • Save it

This will create a new toolbar button allow you to add any selection to a target tiddler.

Screencast

img_869_msedge

Some ideas to use this button

  • take micro notes when editing/writing new tiddler
  • create micro todos with date

Lovely work

Some other ideas to use this button

  • Harvest content from throughout your wiki to compose a new tiddler based on that information.
    • You could have a list of common phrases.
  • Use on tiddlywiki.com (or copy of) to collect code snippets.

Mohamad I think companion buttons in the view toolbar (more) to copy either the title of a tiddler, the title wrapped in [[title]] or the text of the current tiddler to the same target. Here some prior art of mine, not checked today that may speed this. copy-text-title-buttons.json (4.1 KB)

PS Feel free to add your your list/solution as you wish @Mohammad

1 Like

7 posts were split to a new topic: Debugging Tools

Thank you @TW_Tones .
I am wondering how we can access to tiddler title through tm-text-operation or other methods inside editor!

targetTiddler variable for the draft tiddler.

Worth remembering that you can always add <$action-log/> to any action string and see what variables are defined.

2 Likes

Some tips I value related to current tiddler

In addition to target tiddler that @saqimtiaz mentioned storyTiddler variable can help access the current tiddler in the story especialy if currentTiddler has being reused in another list.

But also one thing I discovered is what I call is the focused tiddler. The last navigated to tiddler found here {{$:/HistoryList!!current-tiddler}}
I am not sure it’s appropriate to use in the editor toolbar but it has value. I have supporting tools but again not published.

There is a notable pitfall tv-action-refresh-policythat may cause the button to need to be clicked twice to work.

TW document: https://tiddlywiki.com/#ActionWidget%20Execution%20Modes

My code: fishing/setexcerpt.tid at 987bdaa22dda38c751a33f903e0aee325d98c33d · oflg/fishing · GitHub