Skip to content

Commit fceb2e6

Browse files
authored
feat: add cobalt editor theme (#2484)
1 parent 4c30248 commit fceb2e6

2 files changed

Lines changed: 134 additions & 0 deletions

File tree

‎src/cm/themes/cobalt.js‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
2+
import { EditorView } from "@codemirror/view";
3+
import { tags as t } from "@lezer/highlight";
4+
5+
export const config = {
6+
name: "cobalt",
7+
dark: true,
8+
background: "#002240",
9+
foreground: "#ffffff",
10+
selection: "#b3653966",
11+
cursor: "#ffffff",
12+
dropdownBackground: "#001b33",
13+
dropdownBorder: "#0088ff",
14+
activeLine: "#ffffff0d",
15+
lineNumber: "#7285b7",
16+
lineNumberActive: "#ffffff",
17+
matchingBracket: "#00aaff66",
18+
keyword: "#ffee80",
19+
storage: "#ff9d00",
20+
variable: "#ffffff",
21+
parameter: "#ffffff",
22+
function: "#ffc600",
23+
string: "#3ad900",
24+
constant: "#ff628c",
25+
type: "#80ffbb",
26+
class: "#80ffbb",
27+
number: "#ff628c",
28+
comment: "#0088ff",
29+
heading: "#ffc600",
30+
invalid: "#f8f8f8",
31+
regexp: "#80ffc2",
32+
};
33+
34+
export const cobaltTheme = EditorView.theme(
35+
{
36+
"&": { color: config.foreground, backgroundColor: config.background },
37+
".cm-content": { caretColor: config.cursor },
38+
".cm-cursor, .cm-dropCursor": { borderLeftColor: config.cursor },
39+
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":
40+
{ backgroundColor: config.selection },
41+
".cm-panels": {
42+
backgroundColor: config.dropdownBackground,
43+
color: config.foreground,
44+
},
45+
".cm-panels.cm-panels-top": {
46+
borderBottom: `1px solid ${config.dropdownBorder}`,
47+
},
48+
".cm-panels.cm-panels-bottom": {
49+
borderTop: `1px solid ${config.dropdownBorder}`,
50+
},
51+
".cm-searchMatch": {
52+
backgroundColor: config.matchingBracket,
53+
outline: `1px solid ${config.dropdownBorder}`,
54+
},
55+
".cm-searchMatch.cm-searchMatch-selected, .cm-selectionMatch": {
56+
backgroundColor: config.selection,
57+
},
58+
".cm-activeLine": { backgroundColor: config.activeLine },
59+
"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": {
60+
backgroundColor: config.matchingBracket,
61+
},
62+
".cm-gutters": {
63+
backgroundColor: config.background,
64+
color: config.lineNumber,
65+
border: "none",
66+
},
67+
".cm-activeLineGutter": { backgroundColor: config.activeLine },
68+
".cm-lineNumbers .cm-activeLineGutter": { color: config.lineNumberActive },
69+
".cm-foldPlaceholder": {
70+
backgroundColor: "transparent",
71+
border: "none",
72+
color: config.foreground,
73+
},
74+
".cm-tooltip": {
75+
border: `1px solid ${config.dropdownBorder}`,
76+
backgroundColor: config.dropdownBackground,
77+
color: config.foreground,
78+
},
79+
".cm-tooltip-autocomplete > ul > li[aria-selected]": {
80+
background: config.selection,
81+
color: config.foreground,
82+
},
83+
},
84+
{ dark: config.dark },
85+
);
86+
87+
export const cobaltHighlightStyle = HighlightStyle.define([
88+
{ tag: t.keyword, color: config.keyword },
89+
{ tag: [t.modifier, t.definitionKeyword], color: config.storage },
90+
{
91+
tag: [t.name, t.deleted, t.character, t.macroName],
92+
color: config.variable,
93+
},
94+
{
95+
tag: [t.propertyName, t.function(t.variableName), t.labelName],
96+
color: config.function,
97+
},
98+
{
99+
tag: [t.processingInstruction, t.string, t.inserted, t.special(t.string)],
100+
color: config.string,
101+
},
102+
{
103+
tag: [t.color, t.constant(t.name), t.standard(t.name), t.atom, t.bool],
104+
color: config.constant,
105+
},
106+
{ tag: [t.className, t.typeName], color: config.type },
107+
{
108+
tag: [t.number, t.changed, t.annotation, t.self, t.namespace],
109+
color: config.number,
110+
},
111+
{ tag: [t.operator, t.operatorKeyword], color: config.keyword },
112+
{ tag: [t.url, t.escape, t.regexp, t.link], color: config.regexp },
113+
{ tag: [t.meta, t.comment], color: config.comment, fontStyle: "italic" },
114+
{ tag: t.strong, fontWeight: "bold" },
115+
{ tag: t.emphasis, fontStyle: "italic" },
116+
{ tag: t.link, textDecoration: "underline" },
117+
{ tag: t.heading, fontWeight: "bold", color: config.heading },
118+
{ tag: t.invalid, color: config.invalid, backgroundColor: "#ff0000" },
119+
{ tag: t.strikethrough, textDecoration: "line-through" },
120+
]);
121+
122+
export function cobalt() {
123+
return [cobaltTheme, syntaxHighlighting(cobaltHighlightStyle)];
124+
}
125+
126+
export default cobalt;

‎src/cm/themes/index.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { EditorState } from "@codemirror/state";
22
import { oneDark } from "@codemirror/theme-one-dark";
33
import aura, { config as auraConfig } from "./aura";
44
import ayuDark, { config as ayuDarkConfig } from "./ayuDark";
5+
import cobalt, { config as cobaltConfig } from "./cobalt";
56
import dracula, { config as draculaConfig } from "./dracula";
67
import githubDark, { config as githubDarkConfig } from "./githubDark";
78
import githubLight, { config as githubLightConfig } from "./githubLight";
@@ -161,6 +162,13 @@ export function removeTheme(id) {
161162

162163
addTheme("one_dark", "One Dark", true, () => [oneDark], oneDarkConfig);
163164
addTheme(auraConfig.name, "Aura", !!auraConfig.dark, () => aura(), auraConfig);
165+
addTheme(
166+
cobaltConfig.name,
167+
"Cobalt",
168+
!!cobaltConfig.dark,
169+
() => cobalt(),
170+
cobaltConfig,
171+
);
164172
addTheme(
165173
noctisLilacConfig.name,
166174
noctisLilacConfig.caption || "Noctis Lilac",

0 commit comments

Comments
 (0)