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?
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.
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
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!
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.
@eshvedai did you find a solution to your question yet? I believe we have a similar issue to solve for and I’m curious what solution you came up with.
To elaborate, I would like to decorate an empty selection. For example, let’s imagine I have the characters
text • and our imaginary user entered some different mode I would like to decorate the current cursor position like this:
text [•] (wherein the brackets are some contained span that I can apply some delicious CSS to). When I begin to type in this area, then the style continues, as such: