Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: differentiate methods and properties in dark theme (#3673)

devin-ai-integration[bot]f8e168600110
diff --git a/frontend/src/core/codemirror/cm.ts b/frontend/src/core/codemirror/cm.ts
index 4b044cce82..fd59b3465b 100644
--- a/frontend/src/core/codemirror/cm.ts
+++ b/frontend/src/core/codemirror/cm.ts
@@ -36,8 +36,6 @@ import {
} from "@codemirror/view";
import { EditorState, type Extension, Prec } from "@codemirror/state";
-import { oneDark } from "@codemirror/theme-one-dark";
-
import type { CompletionConfig, KeymapConfig } from "../config/config-schema";
import type { Theme } from "../../theme/useTheme";
@@ -58,6 +56,7 @@ import { historyCompartment } from "./editing/extensions";
import { goToDefinitionBundle } from "./go-to-definition/extension";
import type { HotkeyProvider } from "../hotkeys/hotkeys";
import { lightTheme } from "./theme/light";
+import { darkTheme } from "./theme/dark";
import { dndBundle } from "./misc/dnd";
import { jupyterHelpExtension } from "./compat/jupyter";
import { pasteBundle } from "./misc/paste";
@@ -139,7 +138,7 @@ export const basicBundle = (opts: CodeMirrorSetupOpts): Extension[] => {
parent: document.querySelector<HTMLElement>("#App") ?? undefined,
}),
scrollActiveLineIntoView(),
- theme === "dark" ? oneDark : lightTheme,
+ theme === "dark" ? darkTheme : lightTheme,
hintTooltip(),
copilotBundle(completionConfig),
diff --git a/frontend/src/core/codemirror/theme/dark.ts b/frontend/src/core/codemirror/theme/dark.ts
new file mode 100644
index 0000000000..6991dd6a65
--- /dev/null
+++ b/frontend/src/core/codemirror/theme/dark.ts
@@ -0,0 +1,34 @@
+/* Copyright 2024 Marimo. All rights reserved. */
+import { createTheme } from "thememirror";
+import { tags as t } from "@lezer/highlight";
+
+export const darkTheme = createTheme({
+ variant: "dark",
+ settings: {
+ background: "#282c34",
+ foreground: "#abb2bf",
+ caret: "#528bff",
+ selection: "#3E4451",
+ lineHighlight: "#2c313c",
+ gutterBackground: "var(--color-background)",
+ gutterForeground: "var(--gray-10)",
+ },
+ styles: [
+ { tag: t.comment, color: "#5c6370" },
+ { tag: t.variableName, color: "#abb2bf" },
+ { tag: [t.string, t.special(t.brace)], color: "#98c379" },
+ { tag: t.number, color: "#d19a66" },
+ { tag: t.bool, color: "#d19a66" },
+ { tag: t.null, color: "#d19a66" },
+ { tag: t.keyword, color: "#c678dd", fontWeight: 500 },
+ { tag: t.className, color: "#61afef" },
+ { tag: t.definition(t.typeName), color: "#61afef" },
+ { tag: t.typeName, color: "#56b6c2" },
+ { tag: t.angleBracket, color: "#abb2bf" },
+ { tag: t.tagName, color: "#e06c75" },
+ { tag: t.attributeName, color: "#d19a66" },
+ { tag: t.operator, color: "#56b6c2", fontWeight: 500 },
+ { tag: [t.function(t.variableName)], color: "#61afef" },
+ { tag: [t.propertyName], color: "#e5c07b" },
+ ],
+});
diff --git a/frontend/src/stories/theme.stories.tsx b/frontend/src/stories/theme.stories.tsx
new file mode 100644
index 0000000000..f55b5992ae
--- /dev/null
+++ b/frontend/src/stories/theme.stories.tsx
@@ -0,0 +1,110 @@
+/* Copyright 2024 Marimo. All rights reserved. */
+import type { Meta, StoryObj } from "@storybook/react";
+import React, { useEffect, useRef } from "react";
+import { EditorState, type Extension } from "@codemirror/state";
+import { EditorView } from "@codemirror/view";
+import { basicBundle, type CodeMirrorSetupOpts } from "../core/codemirror/cm";
+import { python } from "@codemirror/lang-python";
+import { OverridingHotkeyProvider } from "../core/hotkeys/hotkeys";
+import { darkTheme } from "../core/codemirror/theme/dark";
+import { lightTheme } from "../core/codemirror/theme/light";
+
+// Partial config for storybook demo
+const demoConfig: Partial<CodeMirrorSetupOpts> = {
+ completionConfig: {
+ activate_on_typing: false,
+ copilot: false,
+ codeium_api_key: null,
+ },
+ hotkeys: new OverridingHotkeyProvider({}),
+ showPlaceholder: false,
+ enableAI: false,
+ keymapConfig: { preset: "default" },
+};
+
+const meta: Meta = {
+ title: "Theme",
+ args: {},
+};
+
+export default meta;
+type Story = StoryObj;
+
+const CONTENT = `
+# Example code to showcase theme differences
+class ExampleClass:
+ def __init__(self, value):
+ self.value = value
+ self.data = {}
+
+ def get_value(self):
+ return self.value
+
+ @property
+ def data_size(self):
+ return len(self.data)
+
+# Create instance and use methods/properties
+example = ExampleClass(42)
+result = example.get_value()
+size = example.data_size
+`.trim();
+
+const Editor = (opts: { extensions?: Extension[] }): React.ReactNode => {
+ const ref = useRef<HTMLDivElement>(null);
+ useEffect(() => {
+ const element = ref.current;
+ if (!element) {
+ return;
+ }
+
+ const view = new EditorView({
+ state: EditorState.create({
+ extensions: opts.extensions,
+ doc: CONTENT,
+ }),
+ parent: element,
+ });
+
+ return () => view.destroy();
+ }, [opts.extensions]);
+
+ return <div className="cm" ref={ref} />;
+};
+
+export const ThemeComparison: Story = {
+ render: () => (
+ <div className="flex gap-4">
+ <div className="w-1/2">
+ <h3 className="mb-2 text-lg font-semibold">Light Theme</h3>
+ <div className="overflow-hidden rounded border">
+ <Editor
+ extensions={[
+ python(),
+ lightTheme,
+ ...basicBundle({
+ ...demoConfig,
+ theme: "light",
+ } as CodeMirrorSetupOpts),
+ ]}
+ />
+ </div>
+ </div>
+ <div className="w-1/2">
+ <h3 className="mb-2 text-lg font-semibold">Dark Theme</h3>
+ <div className="overflow-hidden rounded border">
+ <Editor
+ extensions={[
+ python(),
+ darkTheme,
+ ...basicBundle({
+ ...demoConfig,
+ theme: "dark",
+ } as CodeMirrorSetupOpts),
+ ]}
+ />
+ </div>
+ </div>
+ </div>
+ ),
+};