Skip to content

Commit b534eea

Browse files
committed
Make demo editor reponsive to color scheme changes
It was already using the appropriate theme, but now it also updates if the color scheme preference changes
1 parent 4e4de92 commit b534eea

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/demo/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ formatting: Formatting is supported too! Under the hood this is powered by
102102
103103
`.replace(/:$/m, ': ')
104104

105+
const dark = matchMedia('(prefers-color-scheme: dark)')
106+
editor.setTheme(dark.matches ? 'vs-dark' : 'vs-light')
107+
dark.addEventListener('change', () => {
108+
editor.setTheme(dark.matches ? 'vs-dark' : 'vs-light')
109+
})
110+
105111
const ed = editor.create(document.getElementById('editor')!, {
106112
automaticLayout: true,
107113
model: editor.createModel(value, 'yaml', Uri.parse('monaco-yaml.yaml')),
108-
theme: window.matchMedia('(prefers-color-scheme: dark)').matches ? 'vs-dark' : 'vs-light',
109114
quickSuggestions: {
110115
other: true,
111116
comments: false,

0 commit comments

Comments
 (0)