Block widgets and line decorations

Hi! This might be a stupid question, but can block widgets inherit a line decoration? I have a line decoration for indents and hanging indents, and a block widget can be an image, code chunk output, etc., and the goal is to have the block widgets stay aligned with the indent, so for example if there’s an image link and the text is indented, the image preview widget should also inherit the indent set by a line decoration.

Is there a way to easily handle this? The other approach I’m thinking of is to set the updateDOM of the widget to check the indent of the preceding cm-line and copy the indent style from there. I guess I can check the indent on creation of the widget, but right now the indent line decoration is handled by a different ViewPlugin.

No, you cannot really decorate block widgets. You could add a parameter to the widgets themselves, and pass them the appropriate indentation when creating them, maybe.

That’s not a good idea. updateDOM won’t be called again when the elements around the widget change. This method should only write to its own DOM, not read the DOM of other elements.

1 Like

I see. Thank you for responding!