1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-28 17:39:57 +02:00

add select option to insertNodes

This commit is contained in:
Ian Storm Taylor
2019-12-12 18:50:37 -05:00
parent 262abdc687
commit 31b7ceadc9
2 changed files with 40 additions and 2 deletions

View File

@@ -23,14 +23,14 @@ export const NodeTransforms = {
at?: Location
match?: NodeMatch
hanging?: boolean
select?: boolean
voids?: boolean
} = {}
) {
Editor.withoutNormalizing(editor, () => {
const { selection } = editor
const { hanging = false, voids = false } = options
let { at, match } = options
let select = false
let { at, match, select } = options
if (Node.isNode(nodes)) {
nodes = [nodes]
@@ -57,6 +57,10 @@ export const NodeTransforms = {
select = true
}
if (select == null) {
select = false
}
if (Range.isRange(at)) {
if (!hanging) {
at = Editor.unhangRange(editor, at)

View File

@@ -0,0 +1,34 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../..'
export const input = (
<editor>
<block>
<cursor />
one
</block>
</editor>
)
export const run = editor => {
Editor.insertNodes(
editor,
<block>
<text />
</block>,
{ at: [0], select: true }
)
}
export const output = (
<editor>
<block>
<cursor />
</block>
<block>
one
</block>
</editor>
)