mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 17:53:59 +02:00
Fix path transform for sibling ancestor moves (#3712)
* Fix path transform for sibling ancestor moves * Add some more tests
This commit is contained in:
@@ -386,12 +386,14 @@ export const Path = {
|
|||||||
const copy = onp.slice()
|
const copy = onp.slice()
|
||||||
|
|
||||||
if (Path.endsBefore(op, onp) && op.length < onp.length) {
|
if (Path.endsBefore(op, onp) && op.length < onp.length) {
|
||||||
const i = Math.min(onp.length, op.length) - 1
|
copy[op.length - 1] -= 1
|
||||||
copy[i] -= 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return copy.concat(p.slice(op.length))
|
return copy.concat(p.slice(op.length))
|
||||||
} else if (Path.isSibling(op, p) && Path.equals(onp, p)) {
|
} else if (
|
||||||
|
Path.isSibling(op, onp) &&
|
||||||
|
(Path.isAncestor(onp, p) || Path.equals(onp, p))
|
||||||
|
) {
|
||||||
if (Path.endsBefore(op, p)) {
|
if (Path.endsBefore(op, p)) {
|
||||||
p[op.length - 1] -= 1
|
p[op.length - 1] -= 1
|
||||||
} else {
|
} else {
|
||||||
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [4],
|
||||||
|
newPath: [3],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [4, 3, 3]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [4],
|
||||||
|
newPath: [2],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [4, 3, 3]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [2],
|
||||||
|
newPath: [3],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [2, 3, 3]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [2],
|
||||||
|
newPath: [4],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [2, 3, 3]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [3],
|
||||||
|
newPath: [5, 1],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [4, 1, 3, 3]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [3],
|
||||||
|
newPath: [2, 5],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [2, 5, 3, 3]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [3, 4],
|
||||||
|
newPath: [3, 0, 0],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [3, 3, 3]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [3, 2],
|
||||||
|
newPath: [3, 0, 0],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [3, 2, 3]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [3, 3],
|
||||||
|
newPath: [3, 5, 0],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [3, 4, 0]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [3, 3],
|
||||||
|
newPath: [3, 1, 0],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [3, 1, 0]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [3, 0, 0],
|
||||||
|
newPath: [3, 4],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [3, 3, 3]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [3, 0, 0],
|
||||||
|
newPath: [3, 2],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [3, 4, 3]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [3, 3],
|
||||||
|
newPath: [5, 1],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [5, 1, 3]
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { Path } from 'slate'
|
||||||
|
|
||||||
|
const path = [3, 3, 3]
|
||||||
|
|
||||||
|
const op = {
|
||||||
|
type: 'move_node',
|
||||||
|
path: [3, 3],
|
||||||
|
newPath: [2, 1],
|
||||||
|
}
|
||||||
|
|
||||||
|
export const test = () => {
|
||||||
|
return Path.transform(path, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = [2, 1, 3]
|
Reference in New Issue
Block a user