|
@@ -1,7 +1,10 @@
|
|
|
import { ref, onBeforeUnmount, nextTick } from 'vue'
|
|
import { ref, onBeforeUnmount, nextTick } from 'vue'
|
|
|
|
|
+import { useDesignStore } from '@/store/modules/designStore/designStore'
|
|
|
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js'
|
|
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js'
|
|
|
|
|
|
|
|
export const useMonacoEditor = (language = 'javascript') => {
|
|
export const useMonacoEditor = (language = 'javascript') => {
|
|
|
|
|
+const designStore = useDesignStore()
|
|
|
|
|
+
|
|
|
let monacoEditor: monaco.editor.IStandaloneCodeEditor | null = null
|
|
let monacoEditor: monaco.editor.IStandaloneCodeEditor | null = null
|
|
|
let initReadOnly = false
|
|
let initReadOnly = false
|
|
|
const el = ref<HTMLElement | null>(null)
|
|
const el = ref<HTMLElement | null>(null)
|
|
@@ -29,18 +32,29 @@ export const useMonacoEditor = (language = 'javascript') => {
|
|
|
// 创建
|
|
// 创建
|
|
|
monacoEditor = monaco.editor.create(el.value, {
|
|
monacoEditor = monaco.editor.create(el.value, {
|
|
|
model: javascriptModel,
|
|
model: javascriptModel,
|
|
|
- minimap: { enabled: true },
|
|
|
|
|
- roundedSelection: false,
|
|
|
|
|
- theme: 'vs-dark',
|
|
|
|
|
|
|
+ // 是否启用预览图
|
|
|
|
|
+ minimap: { enabled: false },
|
|
|
|
|
+ // 圆角
|
|
|
|
|
+ roundedSelection: true,
|
|
|
|
|
+ // 主题
|
|
|
|
|
+ theme: designStore.getDarkTheme ? 'vs-dark' : 'vs',
|
|
|
|
|
+ // 主键
|
|
|
multiCursorModifier: 'ctrlCmd',
|
|
multiCursorModifier: 'ctrlCmd',
|
|
|
|
|
+ // 滚动条
|
|
|
scrollbar: {
|
|
scrollbar: {
|
|
|
verticalScrollbarSize: 8,
|
|
verticalScrollbarSize: 8,
|
|
|
horizontalScrollbarSize: 8
|
|
horizontalScrollbarSize: 8
|
|
|
},
|
|
},
|
|
|
|
|
+ // 行号
|
|
|
|
|
+ lineNumbers: 'off',
|
|
|
|
|
+ // tab大小
|
|
|
tabSize: 2,
|
|
tabSize: 2,
|
|
|
- fontSize: 16, //字体大小
|
|
|
|
|
- autoIndent: 'advanced', //自动布局
|
|
|
|
|
- automaticLayout: true, // 自适应宽高
|
|
|
|
|
|
|
+ //字体大小
|
|
|
|
|
+ fontSize: 16,
|
|
|
|
|
+ // 控制编辑器在用户键入、粘贴、移动或缩进行时是否应自动调整缩进
|
|
|
|
|
+ autoIndent: 'advanced',
|
|
|
|
|
+ // 自动布局
|
|
|
|
|
+ automaticLayout: true,
|
|
|
...editorOption
|
|
...editorOption
|
|
|
})
|
|
})
|
|
|
|
|
|