Browse Source

fix bug

feat/icon
谢亚昕 1 week ago
parent
commit
de5f511d6a
  1. 1
      src/renderer/src/components/CodeEditor/a.d.ts
  2. 15
      src/renderer/src/components/CodeEditor/code-editor.vue

1
src/renderer/src/components/CodeEditor/a.d.ts

@ -1 +0,0 @@
type A = string

15
src/renderer/src/components/CodeEditor/code-editor.vue

@ -84,7 +84,7 @@
}, },
}) })
let isInnerChange = false let isInnerChange = "first" // waitting, out, in
function updateModel(name: string, content: string) { function updateModel(name: string, content: string) {
if (editor) { if (editor) {
const oldModel = editor.getModel() // const oldModel = editor.getModel() //
@ -94,7 +94,11 @@
const model: monaco.editor.ITextModel = monaco.editor.createModel(content ?? "", file?.language ?? "txt") const model: monaco.editor.ITextModel = monaco.editor.createModel(content ?? "", file?.language ?? "txt")
model.onDidChangeContent(() => { model.onDidChangeContent(() => {
if (model) { if (model) {
isInnerChange = true if(isInnerChange === "out") {
isInnerChange = "waitting"
return
}
isInnerChange = "in"
const code = model.getValue() const code = model.getValue()
emit("update:modelValue", code) emit("update:modelValue", code)
emit("change", code) emit("change", code)
@ -148,10 +152,13 @@
watch( watch(
() => props.modelValue, () => props.modelValue,
async str => { async str => {
if (editor && !isInnerChange) { if(isInnerChange === "waitting") {
isInnerChange = "out"
}
if (editor && isInnerChange === "out") {
editor.setValue(str) editor.setValue(str)
} else { } else {
isInnerChange = false isInnerChange = "waitting"
} }
}, },
{ immediate: true }, { immediate: true },

Loading…
Cancel
Save