Wanted: editortoolbar button that grabs title of current tiddler and wraps it

Hi everyone

I would like an editor toolbar button that can paste the title of the current tiddler into that tiddler, wrapped fore and aft with text. So, in the tiddler Sapiens (Harari), I would like to click the button to paste

* [[Sapiens (Harari) /]]

(or maybe wrap it with other text like a details element. Not sure yet. I want to experiment with this)

That way I can manually add extensions: ch 2]] … ch 2 / p 9a]]

This would allow me to quickly hard link chapters within books, and notes within chapters, with a breadcrumb-like title for each. Being able to paste like this would save me a lot of time, would help me track reading in a book, and I could use linking in the final note tiddlers to link them to topics.

Another advantage would be that I would not need to add source data for each note. The title, author and page number would be in the title, so when I access a note from a topic (say, in a list of backlinks in a view template), the source data can be seen in the link to the title.

Thanks to anyone who is willing to do this.

This (unworkable example) is close to what I want, but I don’t know how to get it to grab the current title and paste it

\define giffprefix() * [[
\define giffsuffix() /]]

<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="replace-selection"
	text={{{ [TITLE OF CURRENT TIDDLER]addprefix<giffprefix>addsuffix<giffsuffix>]  }}}
/>

Hi Dave,
Try this. The cursor should be at the right position to keep writing.

\define prefix() [[$(realTarget)$/
<$set name="realTarget" value={{{[<targetTiddler>get[draft.of]]}}}>
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="wrap-selection"
	prefix={{{ [<prefix>] }}}
	suffix="]]"
/>
</$set>

For others: There is an example at tw-com how to create a toolbar button. https://tiddlywiki.com/#How%20to%20create%20dynamic%20editor%20toolbar%20buttons

1 Like

I figured it out! That doesn’t happen very often. As I went to post this, I saw Mario posted then deleted something. Thanks for whatever it was!

\define giffprefix() * [[
\define giffsuffix() /]]
\define yuckprefix() Draft of '
\define yucksuffix() '

<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="replace-selection"
	text={{{ [<storyTiddler>removeprefix<yuckprefix>removesuffix<yucksuffix>addprefix<giffprefix>addsuffix<giffsuffix>]  }}}
/>
1 Like

It was similar to the edited post, but without the <$set portion. …
Draft tiddlers have 2 additional temporary fields that can be used.

  • draft.of which contains the title of the tiddler that is edited
  • draft.title contains the content of the title input area. Needed if a tiddler is renamed.

The advantage of the wrap-selection is, that the cursor will be between prefix and suffix. So you should be able to start writing, without the need to relocate the cursor.

1 Like

Thanks Super Mario! This works way better than my solution.

(but I am still proud of having been able to come up with a solution on my own so quickly before seeing what you posted)

4 Likes

Title: [[Pomeranian handbook (author last name) / ch 13 / Grooming]]
text:

notes
[[Pomeranian care]]

Title: [[Pomeranian handbook (author last name) / ch 13 / Baths]]

notes
[[Pomeranian care]]

I learned a new way to use macro in filters, thanks for sharing !
In the interest of sharing other ways to achieve this, here’s how I would do this :

<$action-sendmessage
 $message="tm-edit-text-operation"
 $param="wrap-selection"
 prefix={{{ '[['[<storyTiddler>get[draft.of]]'/'+[join[]] }}}
 suffix="]]"
/>
2 Likes

@telumire That’s a cool way to do it. I will add a bookmark to your post.

1 Like

Thanks Telumire! I concur with Mario, very nice. Both of your answers have been a good learning experience!

1 Like

@DaveGifford I have a handful of ViewToolbar buttons that are click to copy to clipboard, the title in various formats. I am just adding to it now.

Are you interested in them to complement your EditorToolbar buttons?

@TW_Tones While I got my answer three times over for this thread, and my focus was specifically on pasting in edit mode, I would be happy to look at your view buttons, to ponder how I might use them for some other functionality. Blessings!

1 Like

@DaveGifford here is a usable package/prototype

copy-tools-text-title-transclusion-link.json (10.1 KB)

Collection of separate ViewToolbar buttons supporting copy to clipboard

by People, Systems and things (PSaT) TW_Tones

Notes;

  • Hide buttons behind more in View toolbar by unchecking each.

Includes

  • The “Last tiddler” indicator on sidebar.
  • Stores the content of your last copy in $:/history/last-copy
    • Shows in sidebar and can copy again to clipboard
    • If last copy to clipboard was elsewhere.

Futures

  • Optional display condition for each button
  • Unlimited history
1 Like

Perhaps you could add a Editor toolbar button to paste from $:/history/last-copy ?

If you do please shareback

Thanks Tones! Will have a look but it might not be until the weekend. Busy week of taxes, annual planning, and other admin stuff that I have been trying to get to.

1 Like

If you drop it on tiddlywiki.com its all fairly self evident.

No problem, take your time.

Maybe use https://github.com/Gk0Wk/TW5-CodeMirror-Enhanced and it will autocomplete when you type [[ ?