Skip to content

Commit ec0d69e

Browse files
authored
fix: enhance markup comparison performance (#7702)
Signed-off-by: Alexander Onnikov <[email protected]>
1 parent 3fd44ac commit ec0d69e

File tree

1 file changed

+10
-1
lines changed
  • plugins/text-editor-resources/src/components/diff

1 file changed

+10
-1
lines changed

Diff for: plugins/text-editor-resources/src/components/diff/recreate.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import { type Change, diffWordsWithSpace } from 'diff'
2020
import { type Node, type Schema } from '@tiptap/pm/model'
2121
import { ReplaceStep, type Step, Transform } from '@tiptap/pm/transform'
22+
import { deepEqual } from 'fast-equals'
2223
import { applyPatch, createPatch, type Operation } from 'rfc6902'
24+
import { diffAny } from 'rfc6902/diff'
2325
import { type Pointer } from 'rfc6902/pointer'
2426
import { diffArraysPM } from './diff'
2527

@@ -127,6 +129,13 @@ function clone (obj: any): any {
127129
return result
128130
}
129131

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+
130139
export class StepTransform {
131140
schema: Schema
132141
tr: Transform
@@ -147,7 +156,7 @@ export class StepTransform {
147156
this.finalDoc = removeMarks(this.toDoc).toJSON()
148157
this.ops = createPatch(this.currentDoc, this.finalDoc, (input: any, output: any, ptr: Pointer) => {
149158
if (Array.isArray(input) && Array.isArray(output)) {
150-
return diffArraysPM(input, output, ptr)
159+
return diffArraysPM(input, output, ptr, quickDiff)
151160
}
152161
})
153162
this.recreateChangeContentSteps()

0 commit comments

Comments
 (0)