1
0
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:
Kelly Joseph Price
2021-08-10 19:07:11 -07:00
committed by GitHub
parent 4dea740862
commit 479a759108
8 changed files with 187 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
'slate': patch
---
Fix mergeNodes moving node into parent sibling

View File

@@ -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) {

View File

@@ -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>
)

View File

@@ -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>
)

View 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>
)

View 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>
)

View File

@@ -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>
)

View File

@@ -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>
)