mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-13 02:34:05 +02:00
fix: normalizeNode
(#5311)
* fix * Create large-worms-jog.md * Update large-worms-jog.md * Update large-worms-jog.md * Update large-worms-jog.md * fix
This commit is contained in:
5
.changeset/large-worms-jog.md
Normal file
5
.changeset/large-worms-jog.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix #5295 regression. `editor.shouldNormalize` new option: `initialDirtyPathsLength: number`
|
@@ -420,7 +420,7 @@ Check if a value is a void `Element` object.
|
|||||||
|
|
||||||
Override this method to prevent normalizing the editor.
|
Override this method to prevent normalizing the editor.
|
||||||
|
|
||||||
Options: `{ iteration: number; dirtyPaths: Path[]; operation?: Operation(entry: NodeEntry, { operation }`
|
Options: `{ dirtyPaths: Path[]; initialDirtyPathsLength: number; iteration: number; operation?: Operation }`
|
||||||
|
|
||||||
### Callback method
|
### Callback method
|
||||||
|
|
||||||
|
@@ -414,8 +414,8 @@ export const createEditor = (): Editor => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
shouldNormalize: ({ iteration, dirtyPaths }) => {
|
shouldNormalize: ({ iteration, initialDirtyPathsLength }) => {
|
||||||
const maxIterations = dirtyPaths.length * 42 // HACK: better way?
|
const maxIterations = initialDirtyPathsLength * 42 // HACK: better way?
|
||||||
|
|
||||||
if (iteration > maxIterations) {
|
if (iteration > maxIterations) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
@@ -85,6 +85,7 @@ export interface BaseEditor {
|
|||||||
operation,
|
operation,
|
||||||
}: {
|
}: {
|
||||||
iteration: number
|
iteration: number
|
||||||
|
initialDirtyPathsLength: number
|
||||||
dirtyPaths: Path[]
|
dirtyPaths: Path[]
|
||||||
operation?: Operation
|
operation?: Operation
|
||||||
}) => boolean
|
}) => boolean
|
||||||
@@ -1072,15 +1073,16 @@ export const Editor: EditorInterface = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dirtyPaths = getDirtyPaths(editor)
|
let dirtyPaths = getDirtyPaths(editor)
|
||||||
|
const initialDirtyPathsLength = dirtyPaths.length
|
||||||
let iteration = 0
|
let iteration = 0
|
||||||
|
|
||||||
while (getDirtyPaths(editor).length !== 0) {
|
while (dirtyPaths.length !== 0) {
|
||||||
if (
|
if (
|
||||||
!editor.shouldNormalize({
|
!editor.shouldNormalize({
|
||||||
|
dirtyPaths,
|
||||||
iteration,
|
iteration,
|
||||||
dirtyPaths: getDirtyPaths(editor),
|
initialDirtyPathsLength,
|
||||||
operation,
|
operation,
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
@@ -1095,6 +1097,7 @@ export const Editor: EditorInterface = {
|
|||||||
editor.normalizeNode(entry, { operation })
|
editor.normalizeNode(entry, { operation })
|
||||||
}
|
}
|
||||||
iteration++
|
iteration++
|
||||||
|
dirtyPaths = getDirtyPaths(editor)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user