mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-30 20:28:20 +00:00
fix: enhance markup comparison performance (#7702)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
3fd44ac5fe
commit
ec0d69e475
@ -19,7 +19,9 @@
|
|||||||
import { type Change, diffWordsWithSpace } from 'diff'
|
import { type Change, diffWordsWithSpace } from 'diff'
|
||||||
import { type Node, type Schema } from '@tiptap/pm/model'
|
import { type Node, type Schema } from '@tiptap/pm/model'
|
||||||
import { ReplaceStep, type Step, Transform } from '@tiptap/pm/transform'
|
import { ReplaceStep, type Step, Transform } from '@tiptap/pm/transform'
|
||||||
|
import { deepEqual } from 'fast-equals'
|
||||||
import { applyPatch, createPatch, type Operation } from 'rfc6902'
|
import { applyPatch, createPatch, type Operation } from 'rfc6902'
|
||||||
|
import { diffAny } from 'rfc6902/diff'
|
||||||
import { type Pointer } from 'rfc6902/pointer'
|
import { type Pointer } from 'rfc6902/pointer'
|
||||||
import { diffArraysPM } from './diff'
|
import { diffArraysPM } from './diff'
|
||||||
|
|
||||||
@ -127,6 +129,13 @@ function clone (obj: any): any {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const quickDiff = (input: any, output: any, ptr: Pointer): Operation[] => {
|
||||||
|
if (ptr.tokens.length > 4) {
|
||||||
|
return deepEqual(input, output) ? [] : [{ op: 'replace', path: ptr.toString(), value: output }]
|
||||||
|
}
|
||||||
|
return diffAny(input, output, ptr, quickDiff)
|
||||||
|
}
|
||||||
|
|
||||||
export class StepTransform {
|
export class StepTransform {
|
||||||
schema: Schema
|
schema: Schema
|
||||||
tr: Transform
|
tr: Transform
|
||||||
@ -147,7 +156,7 @@ export class StepTransform {
|
|||||||
this.finalDoc = removeMarks(this.toDoc).toJSON()
|
this.finalDoc = removeMarks(this.toDoc).toJSON()
|
||||||
this.ops = createPatch(this.currentDoc, this.finalDoc, (input: any, output: any, ptr: Pointer) => {
|
this.ops = createPatch(this.currentDoc, this.finalDoc, (input: any, output: any, ptr: Pointer) => {
|
||||||
if (Array.isArray(input) && Array.isArray(output)) {
|
if (Array.isArray(input) && Array.isArray(output)) {
|
||||||
return diffArraysPM(input, output, ptr)
|
return diffArraysPM(input, output, ptr, quickDiff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.recreateChangeContentSteps()
|
this.recreateChangeContentSteps()
|
||||||
|
Loading…
Reference in New Issue
Block a user