diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index 2c8e1a35..25b2db8e 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -614,6 +614,16 @@ function WorkspaceApp() { delete root.dataset.webkitScrollWorkaround; }, [webKitScrollWorkaround]); + useEffect(() => { + const root = globalThis.document?.documentElement; + if (!root) return; + + root.dataset.desktopPlatform = desktopPlatform; + return () => { + delete root.dataset.desktopPlatform; + }; + }, [desktopPlatform]); + useEffect(() => { const rememberFocusedEditor = (event: FocusEvent) => { const target = event.target instanceof Element ? event.target : null; diff --git a/packages/app/src/styles.css b/packages/app/src/styles.css index b23f9045..234efefc 100644 --- a/packages/app/src/styles.css +++ b/packages/app/src/styles.css @@ -4641,6 +4641,20 @@ background: color-mix(in srgb, var(--editor-caret-color, var(--accent)) 20%, transparent) !important; } + /* 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. The browser + holds one selection range for one editor, so an unfocused pane or a + multi-range selection keeps the drawn layer. */ + html[data-desktop-platform="linux"] .markdown-paper .cm-editor.cm-focused[data-markra-selection-ranges="single"] .cm-selectionLayer { + display: none !important; + } + + html[data-desktop-platform="linux"] .markdown-paper .cm-editor.cm-focused[data-markra-selection-ranges="single"] .cm-line::selection, + html[data-desktop-platform="linux"] .markdown-paper .cm-editor.cm-focused[data-markra-selection-ranges="single"] .cm-line ::selection { + background: color-mix(in srgb, var(--editor-caret-color, var(--accent)) 20%, transparent) !important; + } + .editor-content-slot[data-document-search-open="true"] .markdown-paper, .editor-content-slot[data-document-search-open="true"] .markdown-paper *, .editor-content-slot[data-document-search-open="true"] .markdown-source-paper, diff --git a/packages/app/src/styles.test.ts b/packages/app/src/styles.test.ts index b9f0f568..d525eb3f 100644 --- a/packages/app/src/styles.test.ts +++ b/packages/app/src/styles.test.ts @@ -125,6 +125,45 @@ describe("editor stylesheet", () => { ); }); + it("paints the preview selection natively on Linux only in the focused single-range editor", () => { + const styles = readFileSync(`${process.cwd()}/src/styles.css`, "utf8"); + const nativeScope = + 'html[data-desktop-platform="linux"] .markdown-paper .cm-editor.cm-focused[data-markra-selection-ranges="single"]'; + const layerSelector = `${nativeScope} .cm-selectionLayer`; + const layerStart = styles.indexOf(`${layerSelector} {`); + const layerRule = styles.slice(layerStart, styles.indexOf("\n }", layerStart)); + const nativeStart = styles.indexOf(`${nativeScope} .cm-line ::selection {`); + const nativeRule = styles.slice(nativeStart, styles.indexOf("\n }", nativeStart)); + + expect(layerRule).toContain("display: none !important"); + expect(nativeRule).toContain( + "background: color-mix(in srgb, var(--editor-caret-color, var(--accent)) 20%, transparent) !important;", + ); + + document.documentElement.dataset.desktopPlatform = "linux"; + document.body.innerHTML = ["focused single", "inactive single", "focused multiple"] + .map((pane) => { + const [focus, ranges] = pane.split(" "); + return `