When the user selects some text, I would like to:
- Wrap selected text in a wrapper node.
- Remove that same wrapper once the text becomes unfocused.
Currently attempting the first hurdle using Decorations but am not having much luck. The decorator is created, but nothing happens.
plugin
new Plugin({
props: {
decorations(state) {
const { to, from } = state.selection;
const decoration = Decoration.node(to, from, {
class: "selected",
});
return DecorationSet.create(state.doc, [decoration]);
}
}
});
decorator
{
"from": 62,
"to": 56,
"type": {
"spec": {},
"attrs": {
"class": "draggable-container",
"nodeName": "span"
}
}
}
Could anyone point me in the right direction?
Thank you!