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

Is it possible to get the position of selected text? #599

Open
khughitt opened this issue Aug 10, 2024 · 1 comment
Open

Is it possible to get the position of selected text? #599

khughitt opened this issue Aug 10, 2024 · 1 comment
Labels

Comments

@khughitt
Copy link

Greetings!

Is there a way to determine the start + end position of selected text?

The goal is to add a custom keyboard short cut which triggers a function that modifies the selected text in a particular way (wraps it in some custom formatting).

The simplest approach seems like it would be to use mde.value() to retrieve the full text, replace the desired subsection, and then call mde.value(..) again to update the content, however, I couldn't figure out a straight-forward way to get the position of the selected region.

Any suggestions?

@ghiscoding
Copy link

ghiscoding commented Aug 26, 2024

I think you can get what you want from the codemirror instance

image

If you really want the char index, then maybe try the .getCursor() in any case, you really have to use the codemirror instance to get these kind of things, see their manual for all available methods

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

No branches or pull requests

2 participants