1
0
Fork 0
polaris-task-force/src/components/frontend/wiki/editorMetrics.ts
Z8MB1E e15b0923ad fix(wiki): align highlight overlay and textarea wrapping so caret/click match painted text
The markdown overlay shared the wrapper's inset-0 box with the transparent-text
textarea, but its inner div added a 1px transparent border while the textarea is
border-0, shrinking its text width by ~2px; Firefox/Safari classic scrollbars
reserve another ~15px inside the scrolled textarea that the overflow-hidden
overlay never sees. Either gutter makes long unbreakable tokens (e.g. image
markdown URLs) wrap differently between the two layers, so the overlay text
drifts vertically under the caret/click math and editing feels like it's one or
more lines off right after inserting an image.

Compose both layers' classes from a shared WIKI_EDITOR_METRICS constant, drop
the overlay border, hide the textarea scrollbar so its content width matches the
overlay in every browser, and lock class parity with a jsdom RTL spec.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-11-18 13:56:10 -05:00

25 lines
1.4 KiB
TypeScript

/**
* Typography + box-model classes that MUST stay identical between the editor
* textarea and the painted highlight overlay underneath it.
*
* The overlay is positioned `absolute inset-0` over the textarea and paints the
* visible text while the textarea keeps `text-transparent`. If the two layers
* ever differ in font size, line height, padding or available content width,
* soft-wrapped lines break at different columns; every difference shifts the
* overlay text vertically against the caret/click geometry of the textarea
* below it. Inserting an image markdown token (`![alt](/media/...png)`, one
* giant unbreakable word) maximizes wrap-point sensitivity, which is why the
* drift becomes obvious right after an upload. Both components import these
* classes from here instead of duplicating them; keep new shared metrics here,
* not inline in either component (see tests/int/wiki-editor-metrics.int.spec.ts).
*/
export const WIKI_EDITOR_METRICS = "px-3 py-2 font-mono text-sm";
/**
* Classic scrollbars (Firefox, Safari, non-overlay Chrome) reserve layout width
* inside the scrolling textarea, shrinking its content width relative to the
* overflow-hidden overlay. Hiding the scrollbar keeps both boxes exactly the
* same width everywhere; wheel/keyboard scrolling and the existing
* caret-into-view logic still work without a draggable thumb.
*/
export const WIKI_EDITOR_SCROLLBAR_NONE = "[scrollbar-width:none] [&::-webkit-scrollbar]:hidden";