mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-21 13:51: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:
parent
7c8eb8e80b
commit
994514b415
@ -386,12 +386,14 @@ export const Path = {
|
||||
const copy = onp.slice()
|
||||
|
||||
if (Path.endsBefore(op, onp) && op.length < onp.length) {
|
||||
const i = Math.min(onp.length, op.length) - 1
|
||||
copy[i] -= 1
|
||||
copy[op.length - 1] -= 1
|
||||
}
|
||||
|
||||
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)) {
|
||||
p[op.length - 1] -= 1
|
||||
} 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]
|
Loading…
x
Reference in New Issue
Block a user