Skip to content

fix(action-preview): skip text the previewed mark cannot go on - #76

Merged
HMarzban merged 24 commits into
mainfrom
fix/preview-skips-code
Nov 15, 2026
Merged

HMarzban merged 24 commits into
mainfrom
fix/preview-skips-code

Conversation

@HMarzban

Copy link
Copy Markdown
Contributor

What and why

Resting on a colour swatch previewed the colour over inline code and code blocks in the selection (for example Red text or Yellow highlight over bun install), although applying never colours them. The preview now shows only what applying does: it skips the text the mark cannot go on, and that text keeps its selection tint.

Root cause

ActionPreview drew one Decoration.inline over each whole selection range. Applying goes through setMark → addMark, which marks only inline nodes whose parent allows the mark (a code block allows none) and that carry no mark excluding it (inlineCode has excludes: "_").

Fix

  • setActionPreview now takes { attrs, mark } | null (PreviewSpec). The eager plugin decorates only the inline nodes addMark would mark, using the schema (parent.type.allowsMarkType, and the Mark.addToSet exclusion rule), and merges adjacent runs into one decoration. The spec is stored on the decorations, so a collaborator's redraw applies the same rule.
  • The lazy swatch side passes the kind's mark (textColor / highlight, for "Default text" and "No highlight" too).
  • A second problem showed up once runs could start after the selection does. A highlight preview is a mark element, so ProseMirror cannot merge the blurred selection's .selection span into it, and nests that span inside the mark instead. Its tint then covered the yellow on the last run. One rule in the lazy color-panel.scss (.tiptap.ProseMirror .tt-preview .selection { background-color: transparent }) keeps it off. Span previews already absorb the class and were not affected.

How verified

  • Unit tests:
    • Inline code is skipped for both marks, and the decorated runs equal exactly what setMark marks.
    • A code block is skipped.
    • Adjacent marked text gets one decoration.
    • An inline-code-only selection shows nothing.
    • A collaborator redraw still skips the code.
    • The hook passes each kind's mark.
  • bun run test: 1241 pass.
  • bun run check, bun run lint and bun run typecheck are clean.
  • New e2e test in action-preview.spec.ts, for Red text and Yellow highlight over a line of text and inline code:
    • The preview covers only the text runs.
    • Nothing previews inside or around code.
    • No selection tint is left inside a highlight preview. I confirmed this check fails without the CSS rule.
    • Applying marks exactly those runs.
  • The new test passed --repeat-each=5.
  • Full action-preview.spec.ts: 25 passed, 4 skipped (screenshot-only). The existing pixel-for-pixel "Default text" / "No highlight" checks now wrap the applied result with the same mark, so both renders skip the same code.
  • Neighbouring specs (text-style-marks, selection-bubble, lazy-surfaces): 49 passed.
  • Before/after screenshots at 1440 and 375, light and dark, dev badge hidden. They cover text and inline code, a paragraph through a code block, and the existing design-review shots of the link/code line and the header cell. I looked at each one.

Bytes

  • Eager editor chunk: +109 B gz (397,407 → 397,516), which is +19,628 B of the 23.5 KB budget (4,436 B left).
  • Palette first Alt+/: 0 B (20,475 before and after, same chunk hashes; it imports no preview code).
  • The CSS rule is in the lazy colour-panel stylesheet.

Follow-ups

  • The WebKit project was not run for action-preview.spec.ts.
  • If a kind is ever enabled for a selection it cannot mark at all, the preview would be empty while the swatch still shows as previewed. Today Tiptap's canSetMark disables the kind in that case, so that path is never reached.

The phone status pill spans the docked bar's width 8px above it, in
the band where the presence and Discord/GitHub/Privacy chips float, so
a refused "/" pick, a removed format's Undo or an unavailable cell's
reason covered them. Hide the chips while the bar holds a pill, as
they already hide for the selection bar; they come back when it closes.
The colour hover preview drew one decoration over each selection range,
so Red text or Yellow highlight showed over inline code and code blocks
although applying never colours them: inlineCode excludes every mark
and a code block allows none.

setActionPreview now takes { attrs, mark } and decorates only the inline
nodes addMark would mark (the parent allows the mark and no mark on the
node excludes it), merging adjacent runs. A collaborator's redraw keeps
the same rule.

A highlight preview's run that starts after the selection nests the
blurred selection's span inside its mark, so the colour panel's
stylesheet keeps that tint off.
A "/" typed while an earlier fetch of the menu chunk was still failing
(the chunk runtime fetches a failed chunk once more, a moment later)
joined that fetch. When it failed, nothing loaded the chunk again while
the menu stayed open, so the menu never showed even once the chunk could
load. A failed load is now fetched once more straight away.
@HMarzban
HMarzban merged commit 2ca87b7 into main Nov 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant