Get link text by cursor position #4716
Unanswered
Dragonite24
asked this question in
Questions & Help
Replies: 3 comments 5 replies
-
Did you ever work this out? I need the same thing. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I use the following snippet to set the link with some content: const selection = editor.view.state.selection;
editor.chain().focus()
.extendMarkRange('link')
.setLink({href: 'http://www.example.org'})
.insertContentAt({from: selection.from, to: selection.to}, 'EditTextAndLink')
.run(); |
Beta Was this translation helpful? Give feedback.
4 replies
-
This worked for me: const { from } = editor.view.state.selection;
const linkNode = editor.state.doc.nodeAt(from);
console.log("linkNode: ", linkNode?.textContent); (I got that based on a partially correct answer from ChatGPT that I was able to make work.) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to do the following functionality:
There is text and a link in it, having focus on the text with the link (the text is not selected, just focus) when you click on some button, I want to be able (in a separate popup component) to change the current link and text.
In the pictures, I want to get out of this:
(...some edit in my popup) to this:
There are no problems with changing the link. But how to get text of link by cursor position? and is it possible?
Beta Was this translation helpful? Give feedback.
All reactions