mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-13 10:44:02 +02:00
* Fix move_node triggers nodes re-render (#5513) * Add changeset
This commit is contained in:
5
.changeset/two-grapes-pump.md
Normal file
5
.changeset/two-grapes-pump.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix move_node triggers nodes re-render
|
@@ -6,6 +6,7 @@ import {
|
|||||||
Node,
|
Node,
|
||||||
Operation,
|
Operation,
|
||||||
Path,
|
Path,
|
||||||
|
PathRef,
|
||||||
Point,
|
Point,
|
||||||
Range,
|
Range,
|
||||||
Transforms,
|
Transforms,
|
||||||
@@ -122,6 +123,7 @@ export const withReact = <T extends BaseEditor>(
|
|||||||
// as apply() changes the object reference and hence invalidates the NODE_TO_KEY entry
|
// as apply() changes the object reference and hence invalidates the NODE_TO_KEY entry
|
||||||
e.apply = (op: Operation) => {
|
e.apply = (op: Operation) => {
|
||||||
const matches: [Path, Key][] = []
|
const matches: [Path, Key][] = []
|
||||||
|
const pathRefMatches: [PathRef, Key][] = []
|
||||||
|
|
||||||
const pendingDiffs = EDITOR_TO_PENDING_DIFFS.get(e)
|
const pendingDiffs = EDITOR_TO_PENDING_DIFFS.get(e)
|
||||||
if (pendingDiffs?.length) {
|
if (pendingDiffs?.length) {
|
||||||
@@ -183,6 +185,21 @@ export const withReact = <T extends BaseEditor>(
|
|||||||
Path.parent(op.newPath)
|
Path.parent(op.newPath)
|
||||||
)
|
)
|
||||||
matches.push(...getMatches(e, commonPath))
|
matches.push(...getMatches(e, commonPath))
|
||||||
|
|
||||||
|
let changedPath: Path
|
||||||
|
if (Path.isBefore(op.path, op.newPath)) {
|
||||||
|
matches.push(...getMatches(e, Path.parent(op.path)))
|
||||||
|
changedPath = op.newPath
|
||||||
|
} else {
|
||||||
|
matches.push(...getMatches(e, Path.parent(op.newPath)))
|
||||||
|
changedPath = op.path
|
||||||
|
}
|
||||||
|
|
||||||
|
const changedNode = Node.get(editor, Path.parent(changedPath))
|
||||||
|
const changedNodeKey = ReactEditor.findKey(e, changedNode)
|
||||||
|
const changedPathRef = Editor.pathRef(e, Path.parent(changedPath))
|
||||||
|
pathRefMatches.push([changedPathRef, changedNodeKey])
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,6 +210,13 @@ export const withReact = <T extends BaseEditor>(
|
|||||||
const [node] = Editor.node(e, path)
|
const [node] = Editor.node(e, path)
|
||||||
NODE_TO_KEY.set(node, key)
|
NODE_TO_KEY.set(node, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const [pathRef, key] of pathRefMatches) {
|
||||||
|
if (pathRef.current) {
|
||||||
|
const [node] = Editor.node(e, pathRef.current)
|
||||||
|
NODE_TO_KEY.set(node, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e.setFragmentData = (data: Pick<DataTransfer, 'getData' | 'setData'>) => {
|
e.setFragmentData = (data: Pick<DataTransfer, 'getData' | 'setData'>) => {
|
||||||
|
Reference in New Issue
Block a user