19
19
import { type Change , diffWordsWithSpace } from 'diff'
20
20
import { type Node , type Schema } from '@tiptap/pm/model'
21
21
import { ReplaceStep , type Step , Transform } from '@tiptap/pm/transform'
22
+ import { deepEqual } from 'fast-equals'
22
23
import { applyPatch , createPatch , type Operation } from 'rfc6902'
24
+ import { diffAny } from 'rfc6902/diff'
23
25
import { type Pointer } from 'rfc6902/pointer'
24
26
import { diffArraysPM } from './diff'
25
27
@@ -127,6 +129,13 @@ function clone (obj: any): any {
127
129
return result
128
130
}
129
131
132
+ const quickDiff = ( input : any , output : any , ptr : Pointer ) : Operation [ ] => {
133
+ if ( ptr . tokens . length > 4 ) {
134
+ return deepEqual ( input , output ) ? [ ] : [ { op : 'replace' , path : ptr . toString ( ) , value : output } ]
135
+ }
136
+ return diffAny ( input , output , ptr , quickDiff )
137
+ }
138
+
130
139
export class StepTransform {
131
140
schema : Schema
132
141
tr : Transform
@@ -147,7 +156,7 @@ export class StepTransform {
147
156
this . finalDoc = removeMarks ( this . toDoc ) . toJSON ( )
148
157
this . ops = createPatch ( this . currentDoc , this . finalDoc , ( input : any , output : any , ptr : Pointer ) => {
149
158
if ( Array . isArray ( input ) && Array . isArray ( output ) ) {
150
- return diffArraysPM ( input , output , ptr )
159
+ return diffArraysPM ( input , output , ptr , quickDiff )
151
160
}
152
161
} )
153
162
this . recreateChangeContentSteps ( )
0 commit comments