Skip to content

fix(editor): paint preview selection natively on Linux - #795

Merged
murongg merged 2 commits into
markrahq:v2from
leemour:fix/linux-native-selection
Nov 25, 2026
Merged

murongg merged 2 commits into
markrahq:v2from
leemour:fix/linux-native-selection

Conversation

@leemour

@leemour leemour commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes laggy text selection and scrolling in the visual editor on Linux. Closes #794.

CodeMirror's drawSelection paints 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: set data-desktop-platform on <html>, right next to the existing data-webkit-scroll-workaround effect.
  • packages/app/src/styles.css: on Linux, hide .markdown-paper .cm-selectionLayer and paint the native ::selection of .cm-line with 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

Platform Selection in the visual editor
Linux desktop Native selection, same theme color
macOS and Windows desktop Unchanged
Web Unchanged (the web runtime reports 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 build passed
  • pnpm --filter @markra/app typecheck:test passed
  • pnpm --filter @markra/app test passed, 141 files and 1667 tests
  • Built a .deb with pnpm tauri build --bundles deb and 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.
  • In the inspector, data-desktop-platform="linux" is set, .cm-selectionLayer computes to display: none and .cm-line::selection resolves to the theme color.

Risks

  • With the layer hidden, only the main range of a multi-range selection gets highlighted on Linux (for example after Ctrl+click). Every range still gets its cursor, since the cursor layer is untouched. I haven't checked this one by hand yet.
  • I also haven't checked selection inside a code block by hand. The code block backdrop sits at 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

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>
@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

@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 murongg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/app/src/styles.css Outdated
/* 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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@murongg
murongg merged commit 5f56d43 into markrahq:v2 Nov 25, 2026
22 of 23 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.

[Editor]: Text selection and scrolling lag in paragraphs on Linux

2 participants