Skip to content

How I achieved image sizing, and a question about setNode (Low priority) #1283

@joevallender

Description

@joevallender

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

Screenshot 2021-05-07 at 09 17 58

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!

Metadata

Metadata

Assignees

Labels

DocumentationThe issue or pullrequest is related to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions