|
| 1 | +import { EditorView } from '@codemirror/view'; |
| 2 | +import { HighlightStyle, syntaxHighlighting } from '@codemirror/language' |
| 3 | +import { tags as t } from '@lezer/highlight'; |
| 4 | + |
| 5 | +/* The base styles were copied from google |
| 6 | + highlighting was modified to fit our design and needs */ |
| 7 | +const darkTheme = EditorView.theme({ |
| 8 | + // Targets the outermost editor container |
| 9 | + '&': { |
| 10 | + color: '#e0e0e0', |
| 11 | + backgroundColor: '#1e1e1e', |
| 12 | + height: '100%' |
| 13 | + }, |
| 14 | + |
| 15 | + // Targets the active editing area where text lives |
| 16 | + '.cm-content': { |
| 17 | + caretColor: '#ff0055', // Custom cursor color |
| 18 | + fontFamily: 'monospace' |
| 19 | + }, |
| 20 | + |
| 21 | + // Targets the line that the cursor is currently on |
| 22 | + '.cm-activeLine': { |
| 23 | + backgroundColor: '#2a2a2a' |
| 24 | + }, |
| 25 | + |
| 26 | + // Targets the line numbers sidebar panel |
| 27 | + '.cm-gutters': { |
| 28 | + backgroundColor: '#1e1e1e', |
| 29 | + color: '#858585', |
| 30 | + border: 'none' |
| 31 | + }, |
| 32 | + |
| 33 | + // Targets the active line number specifically |
| 34 | + '.cm-activeLineGutter': { |
| 35 | + color: '#fff', |
| 36 | + backgroundColor: '#2a2a2a' |
| 37 | + }, |
| 38 | + |
| 39 | + // Targets text highlighted/selected by the user |
| 40 | + '.cm-selectionBackground, ::selection': { |
| 41 | + backgroundColor: '#3e4451 !important' |
| 42 | + } |
| 43 | +}, { dark: true }) |
| 44 | + |
| 45 | +const darkHighlightStyle = HighlightStyle.define([ |
| 46 | + { tag: t.keyword, color: '#FFFF8A', fontWeight: 'bold' }, |
| 47 | + { tag: t.string, color: '#FF5CFF' }, |
| 48 | + { tag: t.comment, color: '#6272a4', fontStyle: 'italic' }, |
| 49 | + { tag: t.function(t.variableName), color: '#50fa7b' }, |
| 50 | + { tag: t.variableName, color: '#f8f8f2' }, |
| 51 | + { tag: t.number, color: '#bd93f9' }, |
| 52 | + { tag: t.integer, color: '#bd93f9' }, |
| 53 | + { tag: t.float, color: '#bd93f9' }, |
| 54 | + { tag: t.url, color: '#FFFF00'}, |
| 55 | + { tag: t.className, color: '#ff5555' }, |
| 56 | + { tag: t.namespace, color: '#9b59b6' }, |
| 57 | + { tag: t.meta, color: '#c678dd' }, |
| 58 | + { tag: t.propertyName, color: '#00D100' }, |
| 59 | + { tag: t.unit, color: '#9b59b6'}, |
| 60 | + { tag: t.punctuation, color: '#ffffff' }, |
| 61 | + { tag: t.literal, color: '#f1fa8c' }, |
| 62 | + { tag: t.docString, color: '#6272a4', fontStyle: 'italic' }, |
| 63 | + { tag: t.processingInstruction, color: '#ffffff' }, |
| 64 | + { tag: t.angleBracket, color: '#f65353' }, |
| 65 | + { tag: t.tagName, color: '#f65353' }, |
| 66 | + { tag: t.attributeName, color: '#66d9ef' }, |
| 67 | +]) |
| 68 | + |
| 69 | +export const darkThemeExtension = [ |
| 70 | + darkTheme, |
| 71 | + syntaxHighlighting(darkHighlightStyle) |
| 72 | +] |
0 commit comments