Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: editor dark theme in dark mode #137

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions components/Editor/cairoLangConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export function registerCairoLanguageSupport(_monaco: typeof MonacoEditor) {
],
},
})
_monaco.editor.defineTheme('myTheme', {
_monaco.editor.defineTheme('light-theme', {
base: 'vs',
inherit: true,
rules: [
Expand All @@ -208,5 +208,18 @@ export function registerCairoLanguageSupport(_monaco: typeof MonacoEditor) {
'editor.inactiveSelectionBackground': '#88000015',
},
})
_monaco.editor.setTheme('myTheme')
_monaco.editor.defineTheme('dark-theme', {
base: 'vs-dark',
inherit: true,
rules: [
{
foreground: '#981B64',
token: 'variableinit',
},
],
colors: {
'editor.background': '#141515',
'editor.lineHighlightBackground': '#1e1e1e',
},
})
}
19 changes: 19 additions & 0 deletions components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import copy from 'copy-to-clipboard'
import { Priority, useRegisterActions } from 'kbar'
import { editor } from 'monaco-editor'
import { useRouter } from 'next/router'
import { useTheme } from 'next-themes'

import {
CairoVMApiContext,
Expand Down Expand Up @@ -66,6 +67,8 @@ const Editor = ({ readOnly = false }: Props) => {

const { addToConsoleLog, isThreeColumnLayout } = useContext(AppUiContext)

const { theme } = useTheme()

const [cairoCode, setCairoCode] = useState('')
const [compiledCairoCode, setCompiledCairoCode] = useState(cairoCode)
const [exampleOption, setExampleOption] = useState<number>(0)
Expand All @@ -74,12 +77,28 @@ const Editor = ({ readOnly = false }: Props) => {

const editorRef = useRef<editor.IStandaloneCodeEditor>()
const monaco = useMonaco()

useEffect(() => {
// when theme is changed, we again set theme of editor
if (theme === 'dark') {
monaco?.editor.setTheme('dark-theme')
} else {
monaco?.editor.setTheme('light-theme')
}
}, [monaco?.editor, theme])

const handleEditorDidMount = async (
editor: editor.IStandaloneCodeEditor,
monaco: Monaco,
) => {
editorRef.current = editor
registerCairoLanguageSupport(monaco as any)
// once the editor is mounted we set the user selected theme
if (theme === 'dark') {
monaco.editor.setTheme('dark-theme')
} else {
monaco.editor.setTheme('light-theme')
}
}

const [decorations, setDecorations] = useState([])
Expand Down
Loading