From 5dea15ade9356d691b20808dfa47b4ceb002326a Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Mon, 25 Apr 2022 21:25:13 +0200 Subject: [PATCH] remove background color from cm6 theme --- repl/src/CodeMirror6.jsx | 7 +- repl/src/themes/material-palenight.js | 130 ++++++++++++++++++++++++++ repl/src/tutorial/style.css | 4 + 3 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 repl/src/themes/material-palenight.js diff --git a/repl/src/CodeMirror6.jsx b/repl/src/CodeMirror6.jsx index 24b1899b..341ed0df 100644 --- a/repl/src/CodeMirror6.jsx +++ b/repl/src/CodeMirror6.jsx @@ -3,9 +3,8 @@ import { CodeMirror as _CodeMirror } from 'react-codemirror6'; import { EditorView, Decoration } from '@codemirror/view'; import { StateField, StateEffect } from '@codemirror/state'; import { javascript } from '@codemirror/lang-javascript'; -import { materialPalenight } from 'codemirror6-themes'; - -// EditorView.theme(materialPalenight); +// import { materialPalenight } from 'codemirror6-themes'; +import { materialPalenight } from './themes/material-palenight'; const highlightMark = Decoration.mark({ class: 'cm-highlight' }); const addHighlight = StateEffect.define(); @@ -83,7 +82,7 @@ export default function CodeMirror({ value, onChange, onViewChanged, onCursor, o onChange={onChange} extensions={[ javascript(), - materialPalenight + materialPalenight, // theme, language, ... ]} /> diff --git a/repl/src/themes/material-palenight.js b/repl/src/themes/material-palenight.js new file mode 100644 index 00000000..d50e10c7 --- /dev/null +++ b/repl/src/themes/material-palenight.js @@ -0,0 +1,130 @@ +import { EditorView } from '@codemirror/view'; +import { HighlightStyle, tags as t } from '@codemirror/highlight'; + +/* + Credits for color palette: + + Author: Mattia Astorino (http://github.com/equinusocio) + Website: https://material-theme.site/ +*/ + +const ivory = '#abb2bf', + stone = '#7d8799', // Brightened compared to original to increase contrast + invalid = '#ffffff', + darkBackground = '#21252b', + highlightBackground = 'rgba(0, 0, 0, 0.5)', + // background = '#292d3e', + background = 'transparent', + tooltipBackground = '#353a42', + selection = 'rgba(128, 203, 196, 0.2)', + cursor = '#ffcc00'; + +/// The editor theme styles for Material Palenight. +export const materialPalenightTheme = EditorView.theme( + { + // done + '&': { + color: '#ffffff', + backgroundColor: background, + }, + + // done + '.cm-content': { + caretColor: cursor, + }, + + // done + '&.cm-focused .cm-cursor': { + borderLeftColor: cursor, + }, + + '&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection': { + backgroundColor: selection, + }, + + '.cm-panels': { backgroundColor: darkBackground, color: '#ffffff' }, + '.cm-panels.cm-panels-top': { borderBottom: '2px solid black' }, + '.cm-panels.cm-panels-bottom': { borderTop: '2px solid black' }, + + // done, use onedarktheme + '.cm-searchMatch': { + backgroundColor: '#72a1ff59', + outline: '1px solid #457dff', + }, + '.cm-searchMatch.cm-searchMatch-selected': { + backgroundColor: '#6199ff2f', + }, + + '.cm-activeLine': { backgroundColor: highlightBackground }, + '.cm-selectionMatch': { backgroundColor: '#aafe661a' }, + + '&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket': { + backgroundColor: '#bad0f847', + outline: '1px solid #515a6b', + }, + + // done + '.cm-gutters': { + background, + color: '#676e95', + border: 'none', + }, + + '.cm-activeLineGutter': { + backgroundColor: highlightBackground, + }, + + '.cm-foldPlaceholder': { + backgroundColor: 'transparent', + border: 'none', + color: '#ddd', + }, + + '.cm-tooltip': { + border: 'none', + backgroundColor: tooltipBackground, + }, + '.cm-tooltip .cm-tooltip-arrow:before': { + borderTopColor: 'transparent', + borderBottomColor: 'transparent', + }, + '.cm-tooltip .cm-tooltip-arrow:after': { + borderTopColor: tooltipBackground, + borderBottomColor: tooltipBackground, + }, + '.cm-tooltip-autocomplete': { + '& > ul > li[aria-selected]': { + backgroundColor: highlightBackground, + color: ivory, + }, + }, + }, + { dark: true }, +); + +/// The highlighting style for code in the Material Palenight theme. +export const materialPalenightHighlightStyle = HighlightStyle.define([ + { tag: t.keyword, color: '#c792ea' }, + { tag: t.operator, color: '#89ddff' }, + { tag: t.special(t.variableName), color: '#eeffff' }, + { tag: t.typeName, color: '#f07178' }, + { tag: t.atom, color: '#f78c6c' }, + { tag: t.number, color: '#ff5370' }, + { tag: t.definition(t.variableName), color: '#82aaff' }, + { tag: t.string, color: '#c3e88d' }, + { tag: t.special(t.string), color: '#f07178' }, + { tag: t.comment, color: stone }, + { tag: t.variableName, color: '#f07178' }, + { tag: t.tagName, color: '#ff5370' }, + { tag: t.bracket, color: '#a2a1a4' }, + { tag: t.meta, color: '#ffcb6b' }, + { tag: t.attributeName, color: '#c792ea' }, + { tag: t.propertyName, color: '#c792ea' }, + { tag: t.className, color: '#decb6b' }, + { tag: t.invalid, color: invalid }, +]); + +/// Extension to enable the Material Palenight theme (both the editor theme and +/// the highlight style). +// : Extension +export const materialPalenight = [materialPalenightTheme, materialPalenightHighlightStyle]; diff --git a/repl/src/tutorial/style.css b/repl/src/tutorial/style.css index 2a2e1d06..589ee893 100644 --- a/repl/src/tutorial/style.css +++ b/repl/src/tutorial/style.css @@ -8,6 +8,10 @@ height: inherit !important; } +.cm-editor { + background-color: transparent !important; +} + main { margin: 0 auto; }