editor: add set-theme command

This commit is contained in:
undefined committed 2021-05-05 12:42:27 +08:00
1 parent eca05dd2f0
commit 455f0dc274
2 files changed
+23 -4

No files matched your search

+15 -3
View File
@@ -8,7 +8,7 @@ export const config = {
'quote', 'line', 'code', 'inline-code', 'table', '|', 'quote', 'line', 'code', 'inline-code', 'table', '|',
'upload', 'edit-mode', 'fullscreen', 'export', 'upload', 'edit-mode', 'fullscreen', 'export',
], ],
mode: UserContext.preferredEditorType || 'sv', mode: UserContext.preferredEditorType || 'ir',
toolbarConfig: { toolbarConfig: {
pin: true, pin: true,
}, },
@@ -47,9 +47,11 @@ export default class Editor extends DOMAttachedObject {
origin.parentElement.appendChild(ele); origin.parentElement.appendChild(ele);
const value = $dom.val(); const value = $dom.val();
const { const {
onChange, language = 'markdown', theme = 'vs-light', model = `file://model-${Math.random().toString(16)}`, onChange, language = 'markdown',
theme = UserContext.monacoTheme || 'vs-light',
model = `file://model-${Math.random().toString(16)}`,
} = this.options; } = this.options;
this.model = monaco.editor.createModel(value, language, monaco.Uri.parse(model)); this.model = typeof model === 'string' ? monaco.editor.createModel(value, language, monaco.Uri.parse(model)) : model;
this.editor = monaco.editor.create( this.editor = monaco.editor.create(
ele, ele,
{ {
@@ -62,6 +64,16 @@ export default class Editor extends DOMAttachedObject {
model: this.model, model: this.model,
} }
); );
this.editor.addAction({
id: 'theme-dark',
label: 'Use dark theme',
run: () => monaco.editor.setTheme('vs-dark'),
});
this.editor.addAction({
id: 'theme-light',
label: 'Use light theme',
run: () => monaco.editor.setTheme('vs-light'),
});
this._subscription = this.editor.onDidChangeModelContent(() => { this._subscription = this.editor.onDidChangeModelContent(() => {
const val = this.editor.getValue(); const val = this.editor.getValue();
$dom.val(val); $dom.val(val);
+8 -1
View File
@@ -89,7 +89,14 @@ preferredEditorType:
monaco: Monaco Editor monaco: Monaco Editor
family: markdown family: markdown
category: preference category: preference
value: sv value: monaco
monacoTheme:
type:
vs-dark: VS Dark
vs-light: VS Light
category: preference
value: vs-light
family: markdown
showInvisibleChar: showInvisibleChar:
type: boolean type: boolean
family: highlight family: highlight