fix: broken conditional rendering of codemirror

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
liyasthomas
2021-09-08 20:27:36 +05:30
parent 26c8f35688
commit 66c489da8f

View File

@@ -43,7 +43,7 @@ const DEFAULT_EDITOR_CONFIG: CodeMirror.EditorConfiguration = {
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"], gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
extraKeys: { extraKeys: {
"Ctrl-Space": "autocomplete", "Ctrl-Space": "autocomplete",
} },
} }
/** /**
@@ -115,8 +115,9 @@ export function useCodemirror(
} }
} }
// Boot-up CodeMirror, set the value and listeners const initialize = () => {
onMounted(() => { if (!el.value) return
cm.value = CodeMirror(el.value!, DEFAULT_EDITOR_CONFIG) cm.value = CodeMirror(el.value!, DEFAULT_EDITOR_CONFIG)
setTheme() setTheme()
@@ -130,15 +131,16 @@ export function useCodemirror(
value.value = instance.getValue() value.value = instance.getValue()
} }
}) })
}
// /* TODO: Show autocomplete on typing (this is just for testing) */ // Boot-up CodeMirror, set the value and listeners
// cm.value.on("keyup", (instance, event) => { onMounted(() => {
// if (!instance.state.completionActive && event.key !== "Enter") { initialize()
// instance.showHint()
// }
// })
}) })
// Reinitialize if the target ref updates
watch(el, initialize)
const setTheme = () => { const setTheme = () => {
if (cm.value) { if (cm.value) {
cm.value?.setOption("theme", getThemeName($colorMode.value)) cm.value?.setOption("theme", getThemeName($colorMode.value))