mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-28 01:19:52 +02:00
Fix bug where insertBlock and insertBlockAtRange always inserted the block below the target, even though focus was collapsed to start (#1037)
This commit is contained in:
committed by
Ian Storm Taylor
parent
e79ec24f39
commit
a0c4073f22
@@ -597,7 +597,11 @@ Transforms.insertBlockAtRange = (transform, range, block, options = {}) => {
|
|||||||
const index = parent.nodes.indexOf(startBlock)
|
const index = parent.nodes.indexOf(startBlock)
|
||||||
|
|
||||||
if (startBlock.isVoid) {
|
if (startBlock.isVoid) {
|
||||||
transform.insertNodeByKey(parent.key, index + 1, block, { normalize })
|
let beforeOrAfterIndex = index
|
||||||
|
if (range.isAtEndOf(startBlock)) {
|
||||||
|
beforeOrAfterIndex++
|
||||||
|
}
|
||||||
|
transform.insertNodeByKey(parent.key, beforeOrAfterIndex, block, { normalize })
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (startBlock.isEmpty) {
|
else if (startBlock.isEmpty) {
|
||||||
|
@@ -15,10 +15,10 @@ export default function (state) {
|
|||||||
const next = state
|
const next = state
|
||||||
.transform()
|
.transform()
|
||||||
.select(range)
|
.select(range)
|
||||||
.insertBlock('image')
|
.insertBlock('video')
|
||||||
.apply()
|
.apply()
|
||||||
|
|
||||||
const updated = next.document.getTexts().last()
|
const updated = next.document.getTexts().first()
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
next.selection.toJS(),
|
next.selection.toJS(),
|
||||||
|
@@ -6,3 +6,8 @@ nodes:
|
|||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
text: ""
|
text: ""
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: "Some text"
|
||||||
|
@@ -1,10 +1,15 @@
|
|||||||
|
|
||||||
nodes:
|
nodes:
|
||||||
- kind: block
|
- kind: block
|
||||||
type: image
|
type: video
|
||||||
isVoid: true
|
|
||||||
- kind: block
|
|
||||||
type: image
|
|
||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
text: ""
|
text: ""
|
||||||
|
- kind: block
|
||||||
|
isVoid: true
|
||||||
|
type: image
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: "Some text"
|
||||||
|
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
export default function (state) {
|
||||||
|
const { document, selection } = state
|
||||||
|
const texts = document.getTexts()
|
||||||
|
const first = texts.first()
|
||||||
|
const range = selection.merge({
|
||||||
|
anchorKey: first.key,
|
||||||
|
anchorOffset: 1,
|
||||||
|
focusKey: first.key,
|
||||||
|
focusOffset: 1
|
||||||
|
})
|
||||||
|
|
||||||
|
return state
|
||||||
|
.transform()
|
||||||
|
.insertBlockAtRange(range, 'image')
|
||||||
|
.apply()
|
||||||
|
}
|
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: video
|
||||||
|
isVoid: true
|
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
nodes:
|
nodes:
|
||||||
- kind: block
|
- kind: block
|
||||||
type: image
|
type: video
|
||||||
isVoid: true
|
isVoid: true
|
||||||
- kind: block
|
- kind: block
|
||||||
type: image
|
type: image
|
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: video
|
||||||
|
isVoid: true
|
@@ -2,7 +2,9 @@
|
|||||||
nodes:
|
nodes:
|
||||||
- kind: block
|
- kind: block
|
||||||
type: image
|
type: image
|
||||||
isVoid: true
|
|
||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
text: ""
|
text: ""
|
||||||
|
- kind: block
|
||||||
|
type: video
|
||||||
|
isVoid: true
|
Reference in New Issue
Block a user