From 5b3c700f0034de25e9f494598c6bcf1888073fc3 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Fri, 30 Jun 2023 19:56:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E4=BB=A3=E7=A0=81=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E5=8F=AA=E6=9C=89=E5=9C=A8=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=8F=91=E7=94=9F=E5=8F=98=E5=8C=96=E6=97=B6=E6=89=8D=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor/src/layouts/CodeEditor.vue | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/layouts/CodeEditor.vue b/packages/editor/src/layouts/CodeEditor.vue index ca51ed17..b9e84c40 100644 --- a/packages/editor/src/layouts/CodeEditor.vue +++ b/packages/editor/src/layouts/CodeEditor.vue @@ -81,7 +81,7 @@ const setEditorValue = (v: string | any, m: string | any) => { }; const getEditorValue = () => - props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue(); + (props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || ''; const init = async () => { if (!codeEditor.value) return; @@ -109,13 +109,19 @@ const init = async () => { if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) { e.preventDefault(); e.stopPropagation(); - emit('save', getEditorValue()); + const newValue = getEditorValue(); + values.value = newValue; + emit('save', newValue); } }); if (props.type !== 'diff' && props.autoSave) { vsEditor?.onDidBlurEditorWidget(() => { - emit('save', getEditorValue()); + const newValue = getEditorValue(); + if (values.value !== newValue) { + values.value = newValue; + emit('save', newValue); + } }); } @@ -146,10 +152,20 @@ onUnmounted(() => { }); defineExpose({ + values, + getEditor() { return vsEditor || vsDiffEditor; }, + getVsEditor() { + return vsEditor; + }, + + getVsDiffEditor() { + return vsDiffEditor; + }, + setEditorValue, focus() {