mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 09:59:48 +02:00
Fix inverse of sibling move operation (#3691)
* Fix path transform against sibling move operations * Fix my jibberish * Add some comments
This commit is contained in:
@@ -228,9 +228,18 @@ export const Operation = {
|
|||||||
return op
|
return op
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to get the original path here, but sometimes the `newPath`
|
// If the move happens completely within a single parent the path and
|
||||||
// is a younger sibling of (or ends before) the original, and this
|
// newPath are stable with respect to each other.
|
||||||
// accounts for it.
|
if (Path.isSibling(path, newPath)) {
|
||||||
|
return { ...op, path: newPath, newPath: path }
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the move does not happen within a single parent it is possible
|
||||||
|
// for the move to impact the true path to the location where the node
|
||||||
|
// was removed from and where it was inserted. We have to adjust for this
|
||||||
|
// and find the original path. We can accomplish this (only in non-sibling)
|
||||||
|
// moves by looking at the impact of the move operation on the node
|
||||||
|
// after the original move path.
|
||||||
const inversePath = Path.transform(path, op)!
|
const inversePath = Path.transform(path, op)!
|
||||||
const inverseNewPath = Path.transform(Path.next(path), op)!
|
const inverseNewPath = Path.transform(Path.next(path), op)!
|
||||||
return { ...op, path: inversePath, newPath: inverseNewPath }
|
return { ...op, path: inversePath, newPath: inverseNewPath }
|
||||||
|
@@ -0,0 +1,9 @@
|
|||||||
|
import { Operation } from 'slate'
|
||||||
|
|
||||||
|
export const input = { type: 'move_node', path: [0, 2], newPath: [0, 1] }
|
||||||
|
|
||||||
|
export const test = value => {
|
||||||
|
return Operation.inverse(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = { type: 'move_node', path: [0, 1], newPath: [0, 2] }
|
@@ -0,0 +1,9 @@
|
|||||||
|
import { Operation } from 'slate'
|
||||||
|
|
||||||
|
export const input = { type: 'move_node', path: [0, 2, 1], newPath: [0, 3] }
|
||||||
|
|
||||||
|
export const test = value => {
|
||||||
|
return Operation.inverse(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = { type: 'move_node', path: [0, 3], newPath: [0, 2, 1] }
|
@@ -0,0 +1,9 @@
|
|||||||
|
import { Operation } from 'slate'
|
||||||
|
|
||||||
|
export const input = { type: 'move_node', path: [0, 2, 1], newPath: [0, 1] }
|
||||||
|
|
||||||
|
export const test = value => {
|
||||||
|
return Operation.inverse(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = { type: 'move_node', path: [0, 1], newPath: [0, 3, 1] }
|
@@ -0,0 +1,12 @@
|
|||||||
|
import { Operation } from 'slate'
|
||||||
|
|
||||||
|
// This test covers moving a child to the location of where the current parent is (not becoming its parent).
|
||||||
|
// When the move happens the child is inserted infront of its old parent causing its former parent's index to shiftp
|
||||||
|
// back within its former grandparent (now parent).
|
||||||
|
export const input = { type: 'move_node', path: [0, 2, 1], newPath: [0, 2] }
|
||||||
|
|
||||||
|
export const test = value => {
|
||||||
|
return Operation.inverse(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = { type: 'move_node', path: [0, 2], newPath: [0, 3, 1] }
|
@@ -0,0 +1,9 @@
|
|||||||
|
import { Operation } from 'slate'
|
||||||
|
|
||||||
|
export const input = { type: 'move_node', path: [0, 3], newPath: [0, 2, 1] }
|
||||||
|
|
||||||
|
export const test = value => {
|
||||||
|
return Operation.inverse(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = { type: 'move_node', path: [0, 2, 1], newPath: [0, 3] }
|
@@ -0,0 +1,10 @@
|
|||||||
|
import { Operation } from 'slate'
|
||||||
|
|
||||||
|
export const input = { type: 'move_node', path: [0, 1], newPath: [0, 2, 1] }
|
||||||
|
|
||||||
|
export const test = value => {
|
||||||
|
return Operation.inverse(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The path has changed here because the removal of [0, 1] caused [0, 2] to shift forward into its location.
|
||||||
|
export const output = { type: 'move_node', path: [0, 1, 1], newPath: [0, 1] }
|
@@ -0,0 +1,9 @@
|
|||||||
|
import { Operation } from 'slate'
|
||||||
|
|
||||||
|
export const input = { type: 'move_node', path: [0, 1], newPath: [0, 2] }
|
||||||
|
|
||||||
|
export const test = value => {
|
||||||
|
return Operation.inverse(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = { type: 'move_node', path: [0, 2], newPath: [0, 1] }
|
@@ -0,0 +1,9 @@
|
|||||||
|
import { Operation } from 'slate'
|
||||||
|
|
||||||
|
export const input = { type: 'move_node', path: [0, 2], newPath: [1, 0, 0] }
|
||||||
|
|
||||||
|
export const test = value => {
|
||||||
|
return Operation.inverse(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = { type: 'move_node', path: [1, 0, 0], newPath: [0, 2] }
|
Reference in New Issue
Block a user