mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-06-16 18:09:22 +08:00
fix(editor): 代码编辑器只有在内容发生变化时才触发保存
This commit is contained in:
parent
42b043670e
commit
5b3c700f00
@ -81,7 +81,7 @@ const setEditorValue = (v: string | any, m: string | any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getEditorValue = () =>
|
const getEditorValue = () =>
|
||||||
props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue();
|
(props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue()) || '';
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
if (!codeEditor.value) return;
|
if (!codeEditor.value) return;
|
||||||
@ -109,13 +109,19 @@ const init = async () => {
|
|||||||
if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
|
if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
emit('save', getEditorValue());
|
const newValue = getEditorValue();
|
||||||
|
values.value = newValue;
|
||||||
|
emit('save', newValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (props.type !== 'diff' && props.autoSave) {
|
if (props.type !== 'diff' && props.autoSave) {
|
||||||
vsEditor?.onDidBlurEditorWidget(() => {
|
vsEditor?.onDidBlurEditorWidget(() => {
|
||||||
emit('save', getEditorValue());
|
const newValue = getEditorValue();
|
||||||
|
if (values.value !== newValue) {
|
||||||
|
values.value = newValue;
|
||||||
|
emit('save', newValue);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,10 +152,20 @@ onUnmounted(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
|
values,
|
||||||
|
|
||||||
getEditor() {
|
getEditor() {
|
||||||
return vsEditor || vsDiffEditor;
|
return vsEditor || vsDiffEditor;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getVsEditor() {
|
||||||
|
return vsEditor;
|
||||||
|
},
|
||||||
|
|
||||||
|
getVsDiffEditor() {
|
||||||
|
return vsDiffEditor;
|
||||||
|
},
|
||||||
|
|
||||||
setEditorValue,
|
setEditorValue,
|
||||||
|
|
||||||
focus() {
|
focus() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user