mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-17 12:41:44 +02: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:
committed by
Ian Storm Taylor
parent
a10f0a7935
commit
10cfb6e48b
@@ -261,14 +261,12 @@ const Transforms = {
|
|||||||
|
|
||||||
// If the range is at the start of the block, insert before.
|
// If the range is at the start of the block, insert before.
|
||||||
else if (range.isAtStartOf(startBlock)) {
|
else if (range.isAtStartOf(startBlock)) {
|
||||||
nodes = nodes.concat(parent.nodes)
|
parent = parent.insertChildrenBefore(startBlock, nodes)
|
||||||
parent = parent.merge({ nodes })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the range is at the end of the block, insert after.
|
// If the range is at the end of the block, insert after.
|
||||||
else if (range.isAtEndOf(startBlock)) {
|
else if (range.isAtEndOf(startBlock)) {
|
||||||
nodes = parent.nodes.concat(nodes)
|
parent = parent.insertChildrenAfter(startBlock, nodes)
|
||||||
parent = parent.merge({ nodes })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, split the block and insert between.
|
// Otherwise, split the block and insert between.
|
||||||
|
@@ -5,3 +5,14 @@ nodes:
|
|||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
text: word
|
text: word
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: word
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: word
|
||||||
|
@@ -10,3 +10,19 @@ nodes:
|
|||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
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
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
export default function (state) {
|
export default function (state) {
|
||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
const texts = document.getTexts()
|
const texts = document.getTexts()
|
||||||
const first = texts.first()
|
const first = texts.last()
|
||||||
const range = selection.merge({
|
const range = selection.merge({
|
||||||
anchorKey: first.key,
|
anchorKey: first.key,
|
||||||
anchorOffset: 0,
|
anchorOffset: 0,
|
||||||
|
@@ -5,3 +5,14 @@ nodes:
|
|||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
text: word
|
text: word
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: word
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: word
|
||||||
|
@@ -10,3 +10,19 @@ nodes:
|
|||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
text: word
|
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
|
||||||
|
Reference in New Issue
Block a user