@@ -185,12 +185,18 @@ export const QuillEditor = defineComponent({
185
185
)
186
186
}
187
187
188
+ const maybeClone = ( delta : Delta | string ) => {
189
+ return typeof delta === 'object' ? delta . slice ( ) : delta
190
+ }
191
+
188
192
const deltaHasValuesOtherThanRetain = ( delta : Delta ) : boolean => {
189
- return Object . values ( delta ) . some ( ( v ) => ! v . retain )
193
+ return Object . values ( delta . ops ) . some (
194
+ ( v ) => ! v . retain || Object . keys ( v ) . length !== 1
195
+ )
190
196
}
191
197
192
- // eslint-disable-next-line vue/no-setup-props-destructure
193
- let internalModel = props . content // Doesn't need reactivity
198
+ // Doesn't need reactivity, but does need to be cloned to avoid deep mutations always registering as equal
199
+ let internalModel : typeof props . content
194
200
const internalModelEquals = ( against : Delta | String | undefined ) => {
195
201
if ( typeof internalModel === typeof against ) {
196
202
if ( against === internalModel ) {
@@ -211,10 +217,7 @@ export const QuillEditor = defineComponent({
211
217
oldContents : Delta ,
212
218
source : Sources
213
219
) => {
214
- // Quill should never be null at this point because we receive an event
215
- // so content should not be undefined but let's make ts and eslint happy
216
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
217
- internalModel = getContents ( ) !
220
+ internalModel = maybeClone ( getContents ( ) as string | Delta )
218
221
// Update v-model:content when text changes
219
222
if ( ! internalModelEquals ( props . content ) ) {
220
223
ctx . emit ( 'update:content' , internalModel )
@@ -302,6 +305,7 @@ export const QuillEditor = defineComponent({
302
305
} else {
303
306
quill ?. setContents ( content as Delta , source )
304
307
}
308
+ internalModel = maybeClone ( content )
305
309
}
306
310
307
311
const getText = ( index ?: number , length ?: number ) : string => {
@@ -338,14 +342,14 @@ export const QuillEditor = defineComponent({
338
342
( newContent ) => {
339
343
if ( ! quill || ! newContent || internalModelEquals ( newContent ) ) return
340
344
341
- internalModel = newContent
342
345
// Restore the selection and cursor position after updating the content
343
346
const selection = quill . getSelection ( )
344
347
if ( selection ) {
345
348
nextTick ( ( ) => quill ?. setSelection ( selection ) )
346
349
}
347
350
setContents ( newContent )
348
- }
351
+ } ,
352
+ { deep : true }
349
353
)
350
354
351
355
watch (
0 commit comments