Repository navigation
fix(editor): paint preview selection natively on Linux - #795
Conversation
WebKitGTK repaints CodeMirror's absolutely positioned selection layer on every pointer move. On Linux (measured on Wayland, AMD, WebKitGTK 2.52 with the DMABUF renderer off) this made drag selection in paragraphs and scrolling visibly lag, while table cells, which use native selection, stayed instant. Editor work per selection step was about 3.5 ms, so the time went into painting, not JavaScript. Expose the desktop platform on the root element and, on Linux only, hide the selection layer and paint the native ::selection with the same theme color. Other platforms keep the drawn layer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@leemour is attempting to deploy a commit to the murongg's projects Team on Vercel. A member of the Team first needs to authorize it. |
murongg
left a comment
There was a problem hiding this comment.
Please preserve selection highlighting in the inactive editor when two documents are open side by side. The stylesheet tests passed. I reproduced the loss of highlight with two Markra editor surfaces in Chromium using the Linux CSS selector. WebKitGTK behavior and scrolling performance still need desktop verification.
| /* WebKitGTK repaints CodeMirror's absolutely positioned selection layer on | ||
| every pointer move, which makes drag selection and scrolling lag. The | ||
| native selection paints in place with the same theme color. */ | ||
| html[data-desktop-platform="linux"] .markdown-paper .cm-selectionLayer { |
There was a problem hiding this comment.
[P2] Keep the selection visible in the inactive pane. Select text in the left editor, then select text in the right editor. The left CodeMirror state still has its selection, but the browser selection belongs to the right editor and this rule hides the left pane's drawn highlight. Please scope native painting to a focused editor with a single range and keep the drawn layer for the inactive pane. Add a two-pane regression check.
There was a problem hiding this comment.
Fixed in 1299bee. The editor now tells the styles whether the selection has one range or several, and the Linux rule only applies to a focused editor with a single range. The inactive pane and multi-range selections keep the drawn layer. Added a two-pane check against the real selector from styles.css. I'll also check it on WebKitGTK locally
Review follow-up for native selection painting on Linux.
The browser holds one selection range for the whole page. With two
documents side by side, selecting in the right pane moved the browser
selection there, and the Linux rule still hid the left pane's drawn layer,
so its CodeMirror selection became invisible. The same happens to the extra
ranges of a multi-range selection.
Expose data-markra-selection-ranges ("single" or "multiple") on the editor
and scope the native painting to .cm-focused editors with a single range.
Unfocused panes and multi-range selections keep CodeMirror's drawn layer.
The stylesheet test now checks the selector against a two-pane DOM.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Fixes laggy text selection and scrolling in the visual editor on Linux. Closes #794.
CodeMirror's
drawSelectionpaints the selection in.cm-selectionLayer, a layer positioned on top of the content. WebKitGTK repaints that layer on every mouse move, so in paragraphs the highlight trails the pointer. Table cells already use the native selection and stay fast. The details and measurements are in the issue.Changes
packages/app/src/App.tsx: setdata-desktop-platformon<html>, right next to the existingdata-webkit-scroll-workaroundeffect.packages/app/src/styles.css: on Linux, hide.markdown-paper .cm-selectionLayerand paint the native::selectionof.cm-linewith the same theme color as.cm-selectionBackground.packages/app/src/styles.test.ts: cover the Linux rules. The existing check against selection layer overrides now looks only at unscoped rules, so the code block layering is still protected on every platform.Behavior
windows)Line geometry doesn't change, since the selection layer is absolutely positioned. The cursor layer stays as it is.
Verification
pnpm --filter @markra/app buildpassedpnpm --filter @markra/app typecheck:testpassedpnpm --filter @markra/app testpassed, 141 files and 1667 testspnpm tauri build --bundles deband used it on Ubuntu 26.04, GNOME Wayland, WebKitGTK 2.52.6. Drag selection in paragraphs follows the mouse now and scrolling doesn't lag anymore.data-desktop-platform="linux"is set,.cm-selectionLayercomputes todisplay: noneand.cm-line::selectionresolves to the theme color.Risks
z-index: -2, so I'd expect the native highlight to show, but it's worth a look.If you'd rather fix this some other way, for example only for WebKitGTK or behind a setting, I'm happy to change it.
I tracked this down together with Claude Code.
🤖 Generated with Claude Code