mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-27 09:04:31 +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)
|
||||
|
||||
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) {
|
||||
|
@@ -15,10 +15,10 @@ export default function (state) {
|
||||
const next = state
|
||||
.transform()
|
||||
.select(range)
|
||||
.insertBlock('image')
|
||||
.insertBlock('video')
|
||||
.apply()
|
||||
|
||||
const updated = next.document.getTexts().last()
|
||||
const updated = next.document.getTexts().first()
|
||||
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
|
@@ -6,3 +6,8 @@ nodes:
|
||||
nodes:
|
||||
- kind: text
|
||||
text: ""
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: "Some text"
|
||||
|
@@ -1,10 +1,15 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
isVoid: true
|
||||
- kind: block
|
||||
type: image
|
||||
type: video
|
||||
nodes:
|
||||
- kind: 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:
|
||||
- kind: block
|
||||
type: image
|
||||
type: video
|
||||
isVoid: true
|
||||
- kind: block
|
||||
type: image
|
@@ -0,0 +1,5 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: video
|
||||
isVoid: true
|
@@ -2,7 +2,9 @@
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
isVoid: true
|
||||
nodes:
|
||||
- kind: text
|
||||
text: ""
|
||||
- kind: block
|
||||
type: video
|
||||
isVoid: true
|
Reference in New Issue
Block a user