If I’m using tiptap editor and, I have the cursor in the middle of a link, I can use editor.getAttributes('link')
to get the link attributes, but how do I get the text contents of that element?
<a href="/">cursor is here</a>
How do I get the text cursor is here
?
I’m trying to build a link UI where you can edit both the content and the href similar to how google docs or wordpress does it.
2
Selecting the link text, then waiting, then accessing the selected text through the state or window.getSelection
seems to work.
this.editor.chain().focus().extendMarkRange('link').run();
window.setTimeout(() => {
const { state } = this.editor;
const { from, to } = state.selection;
console.log(state.doc.textBetween(from, to, ''));
// or
console.log(window.getSelection().toString());
}, 100);