Comments on text
A Mark with an author and comment text, a Bubble menu button and a Text card with the comment under the marked words.
A comment belongs to words, not to a Block, so it is a Mark. Its
attributes are the author and the text. The comment is shown in a
Text card (textCards): a frame under the marked words while the
caret is inside them.
Try it
Put the caret into “by 42%” and a card appears under the words. Select other words and press the comment button in the Bubble menu.
How it works
The Mark and its rules
Mark.create sets behavior (inclusive: false — typing at the edge does not extend the
comment), and the Schema rules set which values are allowed. The comment text is the pattern
[^<>]{1,200}: there is never HTML in an attribute.
One button, two places
selectionMenu: true puts it both on the Toolbar and in the Bubble menu. can disables it
without a selection, isActive highlights it on marked text.
Text card
rangeAt: markRange("acme_comment") is a ready-made kit helper: the stretch with this Mark around
the caret. The kit owns the frame, flipping at the window edge, Escape and the screen reader
phrase, and render draws only the body.
The card is non-modal
Focus stays in the Document and typing goes on; Alt+F10 moves into the card, Escape returns the caret to the Document.
Cards work with readOnly too: comments can be read without editing — see the
“Review mode” Recipe. RichTextView has no cards: it shows sanitized
HTML without the engine.