1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-19 05:31:56 +02:00

fix cursor not correct when insert multiple nodes using insertNodes (#4482)

* fix cursor not correct when insert multiple nodes using insertNodes

* fix lint

* add changeset
This commit is contained in:
JokcyLou
2021-09-07 19:39:47 +08:00
committed by GitHub
parent 1b560de3e1
commit dd752df11d
4 changed files with 73 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
'slate': patch
---
Fix cursor not correct issue after insert multiple nodes with `Transform.insertNodes`

View File

@@ -228,7 +228,9 @@ export const NodeTransforms: NodeTransforms = {
const path = parentPath.concat(index)
index++
editor.apply({ type: 'insert_node', path, node })
at = Path.next(at)
}
at = Path.previous(at)
if (select) {
const point = Editor.end(editor, at)

View File

@@ -0,0 +1,34 @@
/** @jsx jsx */
import { Transforms } from 'slate'
import { jsx } from '../../..'
export const input = (
<editor>
<block>
hel
<cursor />
lo
</block>
</editor>
)
export const run = editor => {
Transforms.insertNodes(editor, [
<inline>
<text />
</inline>,
<text>world</text>,
])
}
export const output = (
<editor>
<block>
hel
<inline>
<text />
</inline>
world
<cursor />
lo
</block>
</editor>
)

View File

@@ -0,0 +1,32 @@
/** @jsx jsx */
import { Transforms } from 'slate'
import { jsx } from '../../..'
export const input = (
<editor>
<block>
hello
<cursor />
</block>
</editor>
)
export const run = editor => {
Transforms.insertNodes(editor, [
<inline>
<text />
</inline>,
<text>world</text>,
])
}
export const output = (
<editor>
<block>
hello
<inline>
<text />
</inline>
world
<cursor />
</block>
</editor>
)