Ability to apply a mark on a range of empty selected cells


#1

Hi,

What would be the best way to apply a mark (lets say “strong”) on a range of empty selected cells?

I tried inserting a widget decoration with “zero-width non-breaking space” text node and strong mark, it didn’t seem to work.

Alternatively I’m thinking about storing these empty cells in plugin state when the mark button is clicked and call toggleMark() whenever cursor gets inside the cell using appendTransaction.

Is there any better way to do that? Thanks!


#2

I’d expect the zero-width space trick to work, but I still don’t think it’s a great direction (because then you have to deal with zero-width spaces left in your document).

But indeed, the document model can’t store marks in empty textblocks, since there’s no content to be marked. You could add an attribute to the textblock nodes to denote a default style for initial content, or, what’s probably cleaner, do what you mention—have a plugin manage these styles.


#3

When I created a decoration widget as “raw” span with ZWNB, I wasn’t able to set cursor outside of the span. As a side effect, my decoration contained all the text I typed as it was content editable, but the node was still empty :slight_smile: Creating it without “raw” param allowed me to type inside paragraph, but it didn’t pick up the mark applied to the widget.

We don’t allow empty text nodes in schema. I guess adding an attribute on a cell and then firing a tr.addStoredMark when cursor moves inside is probably a reasonable alternative in case we wanted to persist the styling (TBD with PM), otherwise I’ll go with plugin state approach. Thanks anyways!


#4

Oh, no, definitely don’t use a decoration widget for this, that doesn’t work (as you found). I thought you were talking about actually inserting a text node with a zero-width space in it and a mark.