mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 06:31:28 +02:00
When trying to move a node from a path to an equal path, ignore it (#2327)
This commit is contained in:
committed by
Ian Storm Taylor
parent
7f65eda65a
commit
7c4c126cd9
@@ -194,6 +194,12 @@ Commands.mergeNodeByPath = (change, path) => {
|
|||||||
Commands.moveNodeByPath = (change, path, newPath, newIndex) => {
|
Commands.moveNodeByPath = (change, path, newPath, newIndex) => {
|
||||||
const { value } = change
|
const { value } = change
|
||||||
|
|
||||||
|
// If the operation path and newPath are the same,
|
||||||
|
// this should be considered a NOOP
|
||||||
|
if (PathUtils.isEqual(path, newPath)) {
|
||||||
|
return change
|
||||||
|
}
|
||||||
|
|
||||||
change.applyOperation({
|
change.applyOperation({
|
||||||
type: 'move_node',
|
type: 'move_node',
|
||||||
value,
|
value,
|
||||||
|
@@ -353,6 +353,10 @@ function getDirtyPaths(operation) {
|
|||||||
let parentPath = PathUtils.lift(path)
|
let parentPath = PathUtils.lift(path)
|
||||||
let newParentPath = PathUtils.lift(newPath)
|
let newParentPath = PathUtils.lift(newPath)
|
||||||
|
|
||||||
|
if (PathUtils.isEqual(path, newPath)) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
// HACK: this clause only exists because the `move_path` logic isn't
|
// HACK: this clause only exists because the `move_path` logic isn't
|
||||||
// consistent when it deals with siblings.
|
// consistent when it deals with siblings.
|
||||||
if (!PathUtils.isSibling(path, newPath)) {
|
if (!PathUtils.isSibling(path, newPath)) {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import Debug from 'debug'
|
import Debug from 'debug'
|
||||||
|
|
||||||
import Operation from '../models/operation'
|
import Operation from '../models/operation'
|
||||||
|
import PathUtils from '../utils/path-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug.
|
* Debug.
|
||||||
@@ -50,6 +51,11 @@ function applyOperation(value, op) {
|
|||||||
|
|
||||||
case 'move_node': {
|
case 'move_node': {
|
||||||
const { path, newPath } = op
|
const { path, newPath } = op
|
||||||
|
|
||||||
|
if (PathUtils.isEqual(path, newPath)) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
const next = value.moveNode(path, newPath)
|
const next = value.moveNode(path, newPath)
|
||||||
return next
|
return next
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,11 @@ function invertOperation(op) {
|
|||||||
|
|
||||||
case 'move_node': {
|
case 'move_node': {
|
||||||
const { newPath, path } = op
|
const { newPath, path } = op
|
||||||
|
|
||||||
|
if (PathUtils.isEqual(newPath, path)) {
|
||||||
|
return op
|
||||||
|
}
|
||||||
|
|
||||||
let inversePath = newPath
|
let inversePath = newPath
|
||||||
let inverseNewPath = path
|
let inverseNewPath = path
|
||||||
|
|
||||||
|
@@ -0,0 +1,34 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
import PathUtils from '../../../../src/utils/path-utils'
|
||||||
|
import assert from 'assert'
|
||||||
|
|
||||||
|
const pathA = PathUtils.create([0])
|
||||||
|
const pathB = PathUtils.create([1])
|
||||||
|
|
||||||
|
export default function(change) {
|
||||||
|
change.moveNodeByPath(pathA, pathA, 0)
|
||||||
|
change.moveNodeByPath(pathA, pathA, 1)
|
||||||
|
change.moveNodeByPath(pathB, pathB, 0)
|
||||||
|
change.moveNodeByPath(pathB, pathB, 1)
|
||||||
|
assert(change.operations.size === 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>1</paragraph>
|
||||||
|
<paragraph>2</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>1</paragraph>
|
||||||
|
<paragraph>2</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
@@ -0,0 +1,29 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
type: 'move_node',
|
||||||
|
path: [0],
|
||||||
|
newPath: [0],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>1</paragraph>
|
||||||
|
<paragraph>2</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>1</paragraph>
|
||||||
|
<paragraph>2</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
Reference in New Issue
Block a user