Can we access the 'selection' in the WidgetMessage: tm-edit-text-operation

If you can manipulate the selection, then I think you can manipulate the text of target tiddler (the one from it you open context menu)

For example highlight selection!

Yes also using freelink plugin as soon as you create the tiddler it will become a highlighted link, but it would be nice to have a operation, like edit-text-operations applied in the text field.

@fastfreddy Can we then insert macros around selected text using this context menu. For example can we add sticky todos (stobot 's plug in) if we select a text and add the todo macro via context menu

1 Like

I believe this is possible then! So you can have an annotation tool!

Of course dynannoate plugin does some of this already.

If it’s an yes, we could do many operations like that from the view mode itself

2 Likes

absolutely @arunnbabu81, the code I pasted as you will see is quite simple (and only adds the wikitext characters for a link to the selection). You can mangle the selection above you wish as @Mohammad suggested, with the one caveat:

One shortcoming noted so far is if the raw text has a line break that is not visible in view mode (or any other fancy wikitext rendering), the search&replace function will not find the selection in the text. I can probably live with that.

Re: Sticky plugin, I think that would be almost trivial, yes, and a great idea :slight_smile:

I also find @saqimtiaz approach to the link context menu to be a bit more modular for these kinds of enhancements, but the : https://context-menu-plugin.tiddlyhost.com plugin isn’t bad either if you are comfortable with javascript.

1 Like

@arunnbabu81 : here’s a minor update which provides two options (create new tiddler from selection, and make todo from selection).

I have added some error checking, type conversion, and the selected words are TitleCased for the new tiddler (using the [[selection|Selection]] text replacement).

You will also need the Stickies — lightweight todo system plugin for the new option.

same caveat: the selected text is from the rendered WikiText; the search-replace is done on the raw WikiText; if the two aren’t identical, the source tiddler replacement will not work.


plugin_fastfreddy_ContextMenuAddin_v0.0.1_20220922.json (9.7 KB)

3 Likes

@fastfreddy I tried to modify the code.

<<sticky "">>

This is the sticky todo macro.

  • I was able to insert the macro only when I changed double-quotes to single quotes in the macro.
    But then the todo macro won’t work then. Is there any way solve this ?
  • Also can we use a widget other than tm-new-tiddler because everytime I tried to insert the macro from the context menu, a new tiddler gets created which is not needed.

This was the mesage I had typed yesterday night before I slept off (was really busy at work yesterday) …when I woke up today , I saw that you have updated it…will check and message today when time permits. Thank you for the fast update.

Yes, this is very true, and it gets even worse if the content are produced from transclusion or some computation like a the output of $list widgets, macros, etc…

I just wondering if dynanotate has the same issues (@Mark_S).

True, but if the selection is not found in the raw tiddler, this tells us it is sourced elsewhere.

  • We could indicate somehow the selection is not in the raw tiddler?, and allow some actions, only if it is found, otherwise open a title or search?
    • Perhaps also consider when found more than once in the raw tiddler or elsewhere.
  • In reality I think such a matter of fact, that what you select is not in the raw tiddler is something a regular user of tiddlywiki would be aware of. Often all they need to do is open a link and rename the tiddler to achieve the equivalent.
  • We could get tricky and wrap code in a var that tells the context menu the official source tiddler if available, thus enabling search and replace in additional cases other than just when in the underlying raw tiddler.
  • I have previously worked out a way to identify the “code tiddler” in which some wiki code exists, which may also help.
    • So a heading “that is in view”, that is in raw text of a transclude/code/macro we would use the code tiddler variable to find the source tiddler on which a search and replace can take place.
    • This would also be helpful to designers, highlight some text on screen and gain a link to the source tiddler.

Out of the box, dynannotate seems to be able to highlight (either through annotation or the search result feature) regardless of origin (raw Wikitext or fancy macro/transclusions). It seems to capture the rendered wikitext and adds position-based overlays to the DOM as follows:

It does not seem to make changes/replacements to the underlying tiddler, but instead creates CSS class-based overlays based on relative position within the DOM object !?!

Interesting…and surprisingly capable… Will continue to investigate, but it may not provide insights if one wishes to change the underlying tiddler with a search/replace functionality…

@fastfreddy have you seen this context menu using wiki text by @Yaisog

Can it be modified to work with macro made by JanJo.


<<ToDo "" "" "">>

Will it by possible to do all basic wiki text formatting using like bold, underline, headings, code blocks with this menu.

yes, all of this is possible and relatively trivial.

yes @arunnbabu81, all of this is relatively trivial, with the one limitation that it works well only when the underlying wikitext is simple text. It will not work when the rendered wikitext stems from macros, transclusions or raw text with line breaks. You should have the building blocks you need in my last json file (or this one with a minor improvements on the wikitext link syntax.)

plugin_fastfreddy_ContextMenuAddin_v0.0.2_20220922.json (9.7 KB)

proof of concept @arunnbabu81

Interestingly, I stumbled another shortcoming. If the word selected appears multiple times, the replacement may or may not occur on the instance you want.
The work around is to substitute all instances which is perhaps what you want, perhaps not.

This json provides will replace all instances of the selection text in the current tiddler for “bold”, “underline”, and “make new tiddler from selection”. For some reason, I don’t think it is appropriate for the sticky todo option, so if multiple matches do exist, only the first one will turn into a todo item.
plugin_fastfreddy_ContextMenuAddin_v0.0.3_20220923.json (11.2 KB)

@fastfreddy I tried to use the version 0.0.3, but seem to be the same as version 0.0.2.

ContextListener.js still has the todo option. Although the bold and underline comes in the context menu, I couldn’t find it in the ContextListener.js

How to modify the code to use this macro ?

please try this repackaged (and refresh, because of javascript). I am confident you can modify the $:/plugins/ahanniga/context-menu/ContextListener.js tiddler to suit your specific needs.

plugin_fastfreddy_ContextMenuAddin_v0.0.4_20220923.json (10.8 KB)

1 Like

This will happen only if the selection is a single word rite. For multi word selections, it will be fine

Tell me what you try that does not work and I will help you troubleshoot.
Look for this portion of $:/plugins/ahanniga/context-menu/ContextListener.js:

case "tm-todo":
            if (selection.trim().length > 0) {
                        $tw.wiki.setText(targ,"text",null,text.replace(selection,"<<sticky \""+selection+"\">>"));
            }
            break;