Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IDEA] Add a textSelection variable to be used by editor toolbar tm-edit-text-operation functions #6949

Open
pmario opened this issue Sep 16, 2022 · 6 comments

Comments

@pmario
Copy link
Contributor

pmario commented Sep 16, 2022

As a user I would like to

  1. select some text
  2. manipulate the text with wikitext functions
  3. the manipulation should be triggered with a button
  4. create a new text in a variable eg: returnText
  5. the returnText should replace the current text selection

That's more or less, what the stamp-function does. ..

The "only" thing missing is a "selectedText" variable that can be used to start with. ...


Original post: https://talk.tiddlywiki.org/t/can-we-access-the-selection-in-the-widgetmessage-tm-edit-text-operation/4558

@Jermolene
Copy link
Owner

Hi @pmario I made a reply to that post explaining why making the text selection available in a variable is not practical. I also suggested an alternative. What is the purpose of opening this discussion?

@pmario
Copy link
Contributor Author

pmario commented Sep 16, 2022

The variable as imagined here is only available to the button actions. It's the exact same behaviour as we use to make variables available for action-widgets.

As I wrote, the stamp function already does most of it. The only thing missing imo is that the eg: ItemTemplate gets access to a selectedText variable, which can be manipulated there.

Once "returnText" is defined a "replace-selection" with the new text can be sent.

@pmario
Copy link
Contributor Author

pmario commented Sep 16, 2022

@Jermolene I did add step 3 "the manipulation should be triggered with a button" to the OP

@saqimtiaz
Copy link
Contributor

I have extended the edit-text widget (in Streams) to both provide the selection as a variable in actions invoked by toolbar buttons as well as the inputActions fired on every key stroke and have not run into any issues.

@saqimtiaz
Copy link
Contributor

I should add though that getting the selection reliably across different editor engines can get tricky and it took some rather fiddly code to extend the simple, framed and codemirror engine to provide a selection variable in actions triggered within the edit widget.

@AnthonyMuscio
Copy link
Contributor

AnthonyMuscio commented Sep 17, 2022

As in this discussion Can we access the ‘selection’ in the WidgetMessage: tm-edit-text-operation telumire details the use of $message="tm-edit-text-operation" $param="save-selection" to place the selection into a tiddler/field.

  • We can then reference this and access the selection.

I was keen to see a slightly more straightforward way to access the selection, as a variable, which clearly every Javascript tm-edit-text-operation can, using operation.selection

An example may be a get selection JS macro result can be assigned to a variable

<$let selection=<<get-selection>>
>
code using selection
</$let>
  • The above can be put inside any actions widgets buttons, editor buttons etc...

Of note if it were possible to do the same outside the editor we could select something and have a button designed to perform an action on the selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants