Skip to content

Commit dbbf71f

Browse files
committed
fix(mdviewer): match selection colors to Phoenix CodeMirror theme
Light: focused #abdffa, unfocused #d5dee3 Dark: focused #0050a0, unfocused #333f48 Uses window focus/blur to toggle .content-focused class since ::selection + :focus doesn't work in WebKit.
1 parent 88a24d5 commit dbbf71f

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

src-mdviewer/src/bridge.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,17 @@ export function initBridge() {
265265
sendToParent("mdviewrCursorSyncToggle", { enabled });
266266
});
267267

268+
// Toggle selection color class based on iframe focus
269+
// (::selection + :focus doesn't work in WebKit)
270+
window.addEventListener("focus", () => {
271+
const content = document.getElementById("viewer-content");
272+
if (content) content.classList.add("content-focused");
273+
});
274+
window.addEventListener("blur", () => {
275+
const content = document.getElementById("viewer-content");
276+
if (content) content.classList.remove("content-focused");
277+
});
278+
268279
// Notify parent that iframe is ready
269280
sendToParent("mdviewrReady", {});
270281
}

src-mdviewer/src/styles/markdown.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,14 @@
412412
margin-bottom: var(--space-sm);
413413
}
414414

415-
/* Selection */
415+
/* Selection — match Phoenix editor selection colors.
416+
Toggled via .content-focused class on window focus/blur since
417+
::selection + :focus doesn't work in WebKit. */
416418
.markdown-body ::selection {
419+
background-color: var(--color-selection-bg-unfocused);
420+
}
421+
422+
.markdown-body.content-focused ::selection {
417423
background-color: var(--color-selection-bg);
418424
}
419425

src-mdviewer/src/styles/themes/dark.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@
5151
--color-table-row-alt: #252526;
5252
--color-table-row-hover: #2D2D2D;
5353

54-
/* Selection */
55-
--color-selection-bg: #539bf533;
54+
/* Selection — match Phoenix CodeMirror selection colors */
55+
--color-selection-bg: #0050a0;
56+
--color-selection-bg-unfocused: #333f48;
5657

5758
/* Search highlight */
5859
--color-highlight: #ae7c1426;

src-mdviewer/src/styles/themes/light.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@
5151
--color-table-row-alt: #f6f8fa;
5252
--color-table-row-hover: #eef3f8;
5353

54-
/* Selection */
55-
--color-selection-bg: #0969da33;
54+
/* Selection — match Phoenix CodeMirror selection colors */
55+
--color-selection-bg: #abdffa;
56+
--color-selection-bg-unfocused: #d5dee3;
5657

5758
/* Search highlight */
5859
--color-highlight: #fff8c5;

0 commit comments

Comments
 (0)