Browse Source

Improve dark mode readability in compose editor

- Use white text (gray-100 #f3f4f6) in editor to match preview
- Set editor background to gray-800 (#1f2937) matching preview
- Lighten preview container from gray-900 to gray-800
- Add explicit text-gray-100 color to preview content
- Lighten tag backgrounds to 40% opacity for better contrast
- Add MutationObserver to detect dark mode changes and recreate editor
- Update cursor, selection, and gutter colors for dark mode

Both editor and preview now have consistent white-on-dark-gray styling
for improved readability in dark mode.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
master
limina1 4 months ago
parent
commit
7c23bb1df3
  1. BIN
      .playwright-mcp/.playwright-mcp/dark-mode-complete.png
  2. BIN
      .playwright-mcp/.playwright-mcp/dark-mode-editor-fix.png
  3. BIN
      .playwright-mcp/.playwright-mcp/dark-mode-final.png
  4. BIN
      .playwright-mcp/.playwright-mcp/dark-mode-preview-update.png
  5. BIN
      .playwright-mcp/.playwright-mcp/dark-mode-text-fix.png
  6. BIN
      .playwright-mcp/.playwright-mcp/dark-mode-white-text.png
  7. BIN
      .playwright-mcp/.playwright-mcp/dark-mode-with-preview.png
  8. BIN
      .playwright-mcp/compose-darkmode-preview.png
  9. BIN
      .playwright-mcp/dark-mode-full-preview.png
  10. BIN
      .playwright-mcp/dark-mode-preview-after.png
  11. BIN
      .playwright-mcp/preview-area.png
  12. 77
      src/lib/components/ZettelEditor.svelte

BIN
.playwright-mcp/.playwright-mcp/dark-mode-complete.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
.playwright-mcp/.playwright-mcp/dark-mode-editor-fix.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
.playwright-mcp/.playwright-mcp/dark-mode-final.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
.playwright-mcp/.playwright-mcp/dark-mode-preview-update.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

BIN
.playwright-mcp/.playwright-mcp/dark-mode-text-fix.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

BIN
.playwright-mcp/.playwright-mcp/dark-mode-white-text.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
.playwright-mcp/.playwright-mcp/dark-mode-with-preview.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

BIN
.playwright-mcp/compose-darkmode-preview.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
.playwright-mcp/dark-mode-full-preview.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
.playwright-mcp/dark-mode-preview-after.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
.playwright-mcp/preview-area.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

77
src/lib/components/ZettelEditor.svelte

@ -60,6 +60,9 @@ @@ -60,6 +60,9 @@
let generatedEvents = $state<any>(null);
let contentType = $state<"article" | "scattered-notes" | "none">("none");
// Dark mode state
let isDarkMode = $state(false);
// Note: updateEditorContent() is only called manually when needed
// The automatic effect was causing feedback loops with user typing
@ -722,6 +725,36 @@ @@ -722,6 +725,36 @@
outline: "none",
},
}),
// Override background and text to match preview (gray-800 bg, gray-100 text)
...(isDarkMode ? [EditorView.theme({
"&": {
backgroundColor: "#1f2937",
color: "#f3f4f6",
},
".cm-content": {
color: "#f3f4f6",
},
".cm-line": {
color: "#f3f4f6",
},
".cm-gutters": {
backgroundColor: "#1f2937",
borderColor: "#374151",
color: "#9ca3af",
},
".cm-activeLineGutter": {
backgroundColor: "#374151",
},
".cm-cursor": {
borderLeftColor: "#f3f4f6",
},
".cm-selectionBackground, ::selection": {
backgroundColor: "#374151 !important",
},
"&.cm-focused .cm-selectionBackground, &.cm-focused ::selection": {
backgroundColor: "#4b5563 !important",
},
}, { dark: true })] : []),
],
});
@ -749,9 +782,41 @@ @@ -749,9 +782,41 @@
// Mount CodeMirror when component mounts
onMount(() => {
// Initialize dark mode state
isDarkMode = document.documentElement.classList.contains('dark');
createEditor();
// Watch for dark mode changes
const observer = new MutationObserver(() => {
const newDarkMode = document.documentElement.classList.contains('dark');
if (newDarkMode !== isDarkMode) {
isDarkMode = newDarkMode;
// Recreate editor with new theme
if (editorView) {
const currentContent = editorView.state.doc.toString();
editorView.destroy();
createEditor();
// Restore content
if (editorView && currentContent !== content) {
editorView.dispatch({
changes: {
from: 0,
to: editorView.state.doc.length,
insert: currentContent,
},
});
}
}
}
});
observer.observe(document.documentElement, {
attributes: true,
attributeFilter: ['class'],
});
return () => {
observer.disconnect();
if (editorView) {
editorView.destroy();
}
@ -887,7 +952,7 @@ @@ -887,7 +952,7 @@
: 'w-full'} flex flex-col"
>
<div
class="flex-1 relative border border-gray-200 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-900"
class="flex-1 relative border border-gray-200 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800"
style="overflow: hidden;"
>
<!-- CodeMirror Editor Container -->
@ -913,7 +978,7 @@ @@ -913,7 +978,7 @@
</h3>
</div>
<div class="flex-1 overflow-y-auto p-6 bg-white dark:bg-gray-900">
<div class="flex-1 overflow-y-auto p-6 bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100">
<div class="max-w-4xl mx-auto">
{#if !content.trim()}
<div
@ -967,7 +1032,7 @@ @@ -967,7 +1032,7 @@
<div class="flex flex-wrap gap-2">
{#each section.tags as tag}
<span
class="bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200 px-2 py-1 rounded-full text-xs font-medium"
class="bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-300 px-2 py-1 rounded-full text-xs font-medium"
>
#{tag[1]}
</span>
@ -1006,7 +1071,7 @@ @@ -1006,7 +1071,7 @@
<div class="flex flex-wrap gap-2">
{#each section.tags as tag}
<span
class="bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200 px-2 py-1 rounded-full text-xs font-medium"
class="bg-green-100 text-green-800 dark:bg-green-900/40 dark:text-green-300 px-2 py-1 rounded-full text-xs font-medium"
>
#{tag[1]}
</span>
@ -1082,7 +1147,7 @@ @@ -1082,7 +1147,7 @@
</div>
<div class="relative flex justify-center">
<span
class="bg-white dark:bg-gray-900 px-3 text-xs text-gray-500 dark:text-gray-400"
class="bg-white dark:bg-gray-800 px-3 text-xs text-gray-500 dark:text-gray-400"
>
Event Boundary
</span>
@ -1094,7 +1159,7 @@ @@ -1094,7 +1159,7 @@
</div>
<div
class="mt-4 text-xs text-gray-600 dark:text-gray-400 bg-gray-50 dark:bg-gray-900 p-2 rounded border"
class="mt-4 text-xs text-gray-600 dark:text-gray-400 bg-gray-50 dark:bg-gray-800 p-2 rounded border"
>
<strong>Event Count:</strong>
{#if generatedEvents}

Loading…
Cancel
Save