Hello everyone, how would you recommend creating a wikitext variable that contains the current text selection? I don’t believe one exists out of the box, but it may be useful to implement, for example, a Create New Tiddler functionality that uses the text selection as title.
Something like <<currentTiddler>> would be nice, e.g. <<textSelection>>.
I think I can answer this question a number of ways
Do you mean to have a global variable name whos value you re-place with the selected text ?
I have in the past looked at adding to every text selection button an action to copy every selection to a data tiddler called “MRU - most recently used selections” so you can access past selections.
I would use it to create a button and keyboard shortcut to rapidly create a new tiddler from the selected text in another tiddler.
I find often that I will write some plain text in a tiddler, and later on, decide to create a tiddler about some of the words/expression I previously used (e.g. provide extra information about it). So the optimal workflow would look like select the text in the paragraph I want to turn into a new tiddler, hit a keyboard sequence, and that would 1) replace the selected text with a wikitext link, and 2) create a new tiddler with the selected text as its title.
As an example, say I create a tiddler about gizmo X, and in the tiddler, state that gizmo X is created by Company Y.
Later on, I may wish to rapidly create a Company Y tiddler. A quick way to do that would be to highlight the words “Company Y”, hit a button/keyboard shortcut, and have that turn into a link and create a new tiddler with the exact title.
Please note that I don’t rely on CamelCase auto-linking normally. I feel it would be a relatively easy problem to solve with a <<textSelection>> core variable (but I am most certainly overlooking a few details).
Can you not make use of the Editor toolbar excise button to do this?
I think that does exactly what you ask for with no need for a variable
Please note you need to wrap code in Discourse with the backtick like in tiddlywiki or we cant read it, that is why I edited your first post. You can also use the code block.
Have you tried the Editor toolbar stamp?
and ‘add your own’
Try this to collect selections, I now see its off topic but share anyway;
Create a tiddler tagged $:/tags/Macro containing
\define selected-text() {{selected-text}}
Create the tiddler selected-text and put some content in it.
Now where you want to use the content use <<selected-text>>
If that works for you we can create an Editor toolbar that uses the setfeild action to set the “selected-text” tiddler to the selection.
ok, will give these ideas a try and report back… Though I wish to be able to do this without having to enter edit mode. Would excise work in view mode?
Cheers!
For one extra step, I have a solution already: I can use the CommandPalette plugin, it has features that lets you define commands that use the selected text as a command parameter. The intermediary step creates the command from the selection and key press, and pops up the basic prompt interface, then the enter key executes the command.
I would normally need not to enter the edit mode, so I would consider options from edit mode to also be one extra step. Still useful information and with some of these I can probably bolt together a “one step” solution.
I know it looks like I am straying from the OT however I belive if I can make this as easy as I can envision it may be a good work around if not solution.
However regardless it would be nice if we could make viewToolbar buttons that can respond to selected content on the rendered tiddler.
Yes precisely, though perhaps the plug-in would work equally well from the edit mode (I can’t think of a reason why it wouldn’t, but I’ll try tomorrow to confirm. It leverages JavaScript for the text selection information and I would expect that to work from either mode)…
It will be hard to create plugin that will work with tiddlers that contain widgets. eg. There are 2 tiddlers
First tiddler
title: test
{{my text}}
Second tiddler
title: my text
Some text and a future link to a book
If you open first tiddler “test” in view mode you will see the transcluded text “Some text and a future link to a book” … So if you select some text, it may be possible to create a tiddler with that selected text, … but it doesn’t make sense to edit the “test” tiddler, because you will need to edit “my text” …
It is even more complex to find the right tiddler to modify if you use list-widget. .. So it should be straight forward to do what you want in edit mode. …
But editing transcluded tiddlers in view mode is a challenge.
Think of the possibilities of having a global core variable that contains the text selection; any widget or macro or filter could use this information and do something useful with it