@@ -185,12 +185,19 @@ export const QuillEditor = defineComponent({
185
185
)
186
186
}
187
187
188
+ const maybeClone = ( delta : Delta | string ) => {
189
+ if ( typeof delta === 'object' ) {
190
+ console . log ( delta . ops , delta . ops === delta . slice ( ) . ops )
191
+ }
192
+ return typeof delta === 'object' ? delta . slice ( ) : delta
193
+ }
194
+
188
195
const deltaHasValuesOtherThanRetain = ( delta : Delta ) : boolean => {
189
196
return Object . values ( delta . ops ) . some ( ( v ) => ! v . retain )
190
197
}
191
198
192
- // eslint-disable-next-line vue/no-setup-props-destructure
193
- let internalModel = props . content // Doesn't need reactivity
199
+ // Doesn't need reactivity, but does need to be cloned to avoid deep mutations always registering as equal
200
+ let internalModel : typeof props . content
194
201
const internalModelEquals = ( against : Delta | String | undefined ) => {
195
202
if ( typeof internalModel === typeof against ) {
196
203
if ( against === internalModel ) {
@@ -214,7 +221,7 @@ export const QuillEditor = defineComponent({
214
221
// Quill should never be null at this point because we receive an event
215
222
// so content should not be undefined but let's make ts and eslint happy
216
223
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
217
- internalModel = getContents ( ) !
224
+ internalModel = maybeClone ( getContents ( ) ! )
218
225
// Update v-model:content when text changes
219
226
if ( ! internalModelEquals ( props . content ) ) {
220
227
ctx . emit ( 'update:content' , internalModel )
@@ -302,6 +309,7 @@ export const QuillEditor = defineComponent({
302
309
} else {
303
310
quill ?. setContents ( content as Delta , source )
304
311
}
312
+ internalModel = maybeClone ( content )
305
313
}
306
314
307
315
const getText = ( index ?: number , length ?: number ) : string => {
@@ -320,7 +328,7 @@ export const QuillEditor = defineComponent({
320
328
if ( quill ) quill . root . innerHTML = html
321
329
}
322
330
323
- const pasteHTML = ( html : string , source : Sources = 'api ' ) => {
331
+ const pasteHTML = ( html : string , source : Sources = 'user ' ) => {
324
332
const delta = quill ?. clipboard . convert ( html as { } )
325
333
if ( delta ) quill ?. setContents ( delta , source )
326
334
}
@@ -338,14 +346,14 @@ export const QuillEditor = defineComponent({
338
346
( newContent ) => {
339
347
if ( ! quill || ! newContent || internalModelEquals ( newContent ) ) return
340
348
341
- internalModel = newContent
342
349
// Restore the selection and cursor position after updating the content
343
350
const selection = quill . getSelection ( )
344
351
if ( selection ) {
345
352
nextTick ( ( ) => quill ?. setSelection ( selection ) )
346
353
}
347
354
setContents ( newContent )
348
- }
355
+ } ,
356
+ { deep : true }
349
357
)
350
358
351
359
watch (
0 commit comments