mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-28 17:39:57 +02:00
Fix mergeNodes moving node into parent sibling (#4296)
* test: add test case for bug
* prefer next will transforming selection in remove_node
* add remove_node test
* Add changeset
* review: handle nested blocks
* refactor
* Revert "refactor"
This reverts commit 45a8aab7cb
.
Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
This commit is contained in:
committed by
GitHub
parent
4dea740862
commit
479a759108
5
.changeset/orange-jeans-sing.md
Normal file
5
.changeset/orange-jeans-sing.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate': patch
|
||||
---
|
||||
|
||||
Fix mergeNodes moving node into parent sibling
|
@@ -150,7 +150,18 @@ const applyToDraft = (editor: Editor, selection: Selection, op: Operation) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (prev) {
|
||||
let preferNext = false
|
||||
if (prev && next) {
|
||||
if (Path.equals(next[1], path)) {
|
||||
preferNext = !Path.hasPrevious(next[1])
|
||||
} else {
|
||||
preferNext =
|
||||
Path.common(prev[1], path).length <
|
||||
Path.common(next[1], path).length
|
||||
}
|
||||
}
|
||||
|
||||
if (prev && !preferNext) {
|
||||
point.path = prev[1]
|
||||
point.offset = prev[0].text.length
|
||||
} else if (next) {
|
||||
|
@@ -0,0 +1,28 @@
|
||||
/** @jsx jsx */
|
||||
import { jsx } from '../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
<text />
|
||||
</block>
|
||||
<block>
|
||||
<block>
|
||||
<cursor />
|
||||
<text />
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>
|
||||
<text />
|
||||
</block>
|
||||
<block>
|
||||
<block>
|
||||
<cursor />
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,24 @@
|
||||
/** @jsx jsx */
|
||||
import { jsx } from '../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
<text />
|
||||
</block>
|
||||
<block>
|
||||
<cursor />
|
||||
<text />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>
|
||||
<text />
|
||||
</block>
|
||||
<block>
|
||||
<cursor />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
35
packages/slate/test/operations/remove_node/cursor-nested.tsx
Normal file
35
packages/slate/test/operations/remove_node/cursor-nested.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
/** @jsx jsx */
|
||||
import { jsx } from 'slate-hyperscript'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<element>
|
||||
<text />
|
||||
</element>
|
||||
<element>
|
||||
<element>
|
||||
<cursor />
|
||||
<text />
|
||||
</element>
|
||||
</element>
|
||||
</editor>
|
||||
)
|
||||
export const operations = [
|
||||
{
|
||||
type: 'remove_node',
|
||||
path: [1, 0, 0],
|
||||
node: { text: '' },
|
||||
},
|
||||
]
|
||||
export const output = (
|
||||
<editor>
|
||||
<element>
|
||||
<text />
|
||||
</element>
|
||||
<element>
|
||||
<element>
|
||||
<cursor />
|
||||
</element>
|
||||
</element>
|
||||
</editor>
|
||||
)
|
31
packages/slate/test/operations/remove_node/cursor.tsx
Normal file
31
packages/slate/test/operations/remove_node/cursor.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
/** @jsx jsx */
|
||||
import { jsx } from 'slate-hyperscript'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<element>
|
||||
<text />
|
||||
</element>
|
||||
<element>
|
||||
<cursor />
|
||||
<text />
|
||||
</element>
|
||||
</editor>
|
||||
)
|
||||
export const operations = [
|
||||
{
|
||||
type: 'remove_node',
|
||||
path: [1, 0],
|
||||
node: { text: '' },
|
||||
},
|
||||
]
|
||||
export const output = (
|
||||
<editor>
|
||||
<element>
|
||||
<text />
|
||||
</element>
|
||||
<element>
|
||||
<cursor />
|
||||
</element>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,28 @@
|
||||
/** @jsx jsx */
|
||||
import { Transforms, Text } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>one</block>
|
||||
<block>
|
||||
<block>
|
||||
<cursor />
|
||||
<text />
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const run = editor => {
|
||||
Transforms.mergeNodes(editor, { at: [1, 0, 1], match: Text.isText })
|
||||
}
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>one</block>
|
||||
<block>
|
||||
<block>
|
||||
<cursor />
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@@ -0,0 +1,24 @@
|
||||
/** @jsx jsx */
|
||||
import { Transforms, Text } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>one</block>
|
||||
<block>
|
||||
<cursor />
|
||||
<text />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const run = editor => {
|
||||
Transforms.mergeNodes(editor, { at: [1, 1], match: Text.isText })
|
||||
}
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>one</block>
|
||||
<block>
|
||||
<cursor />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
Reference in New Issue
Block a user