1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-24 01:02:31 +01:00

Change concat into insertChildrenAfter and insertChildrenBefore (#232)

* Change concat into insertChildrenAfter and insertChildrenBefore

* Update input and out yaml of insert block at range block-end

* Update input and out yaml of insert block at range block-start
This commit is contained in:
Suwijak Chaipipat 2016-08-09 23:10:03 +07:00 committed by Ian Storm Taylor
parent a10f0a7935
commit 10cfb6e48b
6 changed files with 57 additions and 5 deletions

View File

@ -261,14 +261,12 @@ const Transforms = {
// If the range is at the start of the block, insert before.
else if (range.isAtStartOf(startBlock)) {
nodes = nodes.concat(parent.nodes)
parent = parent.merge({ nodes })
parent = parent.insertChildrenBefore(startBlock, nodes)
}
// If the range is at the end of the block, insert after.
else if (range.isAtEndOf(startBlock)) {
nodes = parent.nodes.concat(nodes)
parent = parent.merge({ nodes })
parent = parent.insertChildrenAfter(startBlock, nodes)
}
// Otherwise, split the block and insert between.

View File

@ -5,3 +5,14 @@ nodes:
nodes:
- kind: text
text: word
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: word
- kind: block
type: paragraph
nodes:
- kind: text
text: word

View File

@ -10,3 +10,19 @@ nodes:
nodes:
- kind: text
text: ""
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: word
- kind: block
type: image
nodes:
- kind: text
text: ""
- kind: block
type: paragraph
nodes:
- kind: text
text: word

View File

@ -2,7 +2,7 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const first = texts.last()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,

View File

@ -5,3 +5,14 @@ nodes:
nodes:
- kind: text
text: word
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: word
- kind: block
type: paragraph
nodes:
- kind: text
text: word

View File

@ -10,3 +10,19 @@ nodes:
nodes:
- kind: text
text: word
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: word
- kind: block
type: image
nodes:
- kind: text
text: ""
- kind: block
type: paragraph
nodes:
- kind: text
text: word