@@ -1,6 +1,7 @@
import React, { useState, useEffect, useCallback, useRef } from "react";
import type * as Monaco from "monaco-editor";
import { api } from "../services/api";
+import { isDarkModeActive } from "../services/theme";
import { GitDiffInfo, GitFileInfo, GitFileDiff } from "../types";
interface DiffViewerProps {
@@ -227,7 +228,7 @@ function DiffViewer({ cwd, isOpen, onClose, onCommentTextChange, initialCommit }
// Create diff editor with mobile-friendly options
const diffEditor = monaco.editor.createDiffEditor(editorContainerRef.current, {
- theme: "vs",
+ theme: isDarkModeActive() ? "vs-dark" : "vs",
readOnly: true, // Always read-only in diff viewer
originalEditable: false,
automaticLayout: true,
@@ -578,6 +579,29 @@ function DiffViewer({ cwd, isOpen, onClose, onCommentTextChange, initialCommit }
saveCurrentFile();
}, [saveCurrentFile]);
+ // Update Monaco theme when dark mode changes
+ useEffect(() => {
+ if (!monacoRef.current) return;
+
+ const updateMonacoTheme = () => {
+ const theme = isDarkModeActive() ? "vs-dark" : "vs";
+ monacoRef.current?.editor.setTheme(theme);
+ };
+
+ // Watch for changes to the dark class on documentElement
+ const observer = new MutationObserver((mutations) => {
+ for (const mutation of mutations) {
+ if (mutation.attributeName === "class") {
+ updateMonacoTheme();
+ }
+ }
+ });
+
+ observer.observe(document.documentElement, { attributes: true });
+
+ return () => observer.disconnect();
+ }, [monacoLoaded]);
+
// Keyboard shortcuts
useEffect(() => {
if (!isOpen) return;
@@ -18,6 +18,11 @@ export function getSystemPrefersDark(): boolean {
return window.matchMedia("(prefers-color-scheme: dark)").matches;
}
+export function isDarkModeActive(): boolean {
+ const theme = getStoredTheme();
+ return theme === "dark" || (theme === "system" && getSystemPrefersDark());
+}
+
export function applyTheme(theme: ThemeMode): void {
const isDark = theme === "dark" || (theme === "system" && getSystemPrefersDark());
document.documentElement.classList.toggle("dark", isDark);