|
@@ -26,10 +26,24 @@ watch(
|
|
|
() => getCurrentValue(),
|
|
|
(newValue) => {
|
|
|
const editorVal = getEditorValue();
|
|
|
- if (editor.value && newValue !== editorVal) {
|
|
|
- isUpdatingFromParent = true; // 开锁,标记是外部更新
|
|
|
+ const normalize = (s) => (s || '').trim();
|
|
|
+
|
|
|
+ if (editor.value && normalize(newValue) !== normalize(editorVal)) {
|
|
|
+ console.log('外部更新编辑器内容', newValue);
|
|
|
+ console.log('当前编辑器内容', editorVal);
|
|
|
+
|
|
|
+ isUpdatingFromParent = true;
|
|
|
+
|
|
|
+ // 设置值
|
|
|
editor.value.setValue(newValue || '');
|
|
|
- isUpdatingFromParent = false;
|
|
|
+
|
|
|
+ // 等当前宏任务结束后再解除锁
|
|
|
+ queueMicrotask(() => {
|
|
|
+ isUpdatingFromParent = false;
|
|
|
+ console.log('编辑器内容已更新', editor.value.getValue());
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ console.log('内容相同,跳过更新');
|
|
|
}
|
|
|
}
|
|
|
);
|