diff --git a/src/views/board/BoardEdit.vue b/src/views/board/BoardEdit.vue index 785e781..cb552f1 100644 --- a/src/views/board/BoardEdit.vue +++ b/src/views/board/BoardEdit.vue @@ -141,13 +141,34 @@ } }; - function extractPlainText(delta) { - if (!delta || !Array.isArray(delta.ops)) return ''; - return delta.ops - .filter(op => typeof op.insert === 'string') - .map(op => op.insert.trim()) - .join(' ') - .trim(); + function isDeltaChanged(current, original) { + const Delta = Quill.import('delta'); + const currentDelta = new Delta(current || []); + const originalDelta = new Delta(original || []); + + const diff = originalDelta.diff(currentDelta); + if (!diff || diff.ops.length === 0) return false; + + // 텍스트만 비교해서 완전 동일한지 확인 + const getPlainText = delta => + (delta.ops || []) + .filter(op => typeof op.insert === 'string') + .map(op => op.insert) + .join(''); + + const getImages = delta => + (delta.ops || []).filter(op => typeof op.insert === 'object' && op.insert.image).map(op => op.insert.image); + + const textCurrent = getPlainText(currentDelta); + const textOriginal = getPlainText(originalDelta); + + const imgsCurrent = getImages(currentDelta); + const imgsOriginal = getImages(originalDelta); + + const textEqual = textCurrent === textOriginal; + const imageEqual = JSON.stringify(imgsCurrent) === JSON.stringify(imgsOriginal); + + return !(textEqual && imageEqual); // 둘 다 같아야 false } const isChanged = computed(() => { @@ -212,16 +233,6 @@ contentLoaded.value = true; }; - watch( - content, - val => { - if (contentLoaded.value && !originalPlainText.value) { - originalPlainText.value = extractPlainText(val); - } - }, - { immediate: true }, - ); - const handleUpdateEditorImg = item => { editorUploadedImgList.value = item; };