-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Not really a problem, just sharing some code to possible help others, and a quick question about how to improve the implementation.
I needed to add basic image sizing in tiptap2/vue3 and did so by referring to a mixture of the existing code for image, heading, and bubble menu.
Here is a
Question
My question is about the best way to update the node. The image extension replaces the selection with a new node, and the heading extension runs commands.setNode
which appears to be the cleaner options.
setHeading: attributes => ({ commands }) => {
if (!this.options.levels.includes(attributes.level)) {
return false
}
return commands.setNode('heading', attributes)
},
When setting a size attribute on images, commands.setNode
appeared to have no effect. I guessed that maybe a selected image needs to be treated differently to selected text, but I couldn't work it out. When I'm replacing the selection, changing between image sizes isn't as slick as I would like because of the delay in the browser re-drawing the image node. I'm wondering if I can get setNode to work, it might simply update the attributes, and keep things smoother?
If you can clarify, and I can better understand, I'd be happy to work on a more fully featured image extension.
And, thanks for tiptap!