mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-02 03:32:36 +02:00
simplify before-inline split-block test
This commit is contained in:
@@ -312,10 +312,27 @@ export function splitBlock(transform, depth = 1) {
|
|||||||
state = transform.state
|
state = transform.state
|
||||||
document = state.document
|
document = state.document
|
||||||
|
|
||||||
const { startKey } = selection
|
const { startKey, startOffset } = selection
|
||||||
const startNode = document.getDescendant(startKey)
|
const startText = document.getNode(startKey)
|
||||||
const nextNode = document.getNextText(startNode.key)
|
const startBlock = document.getClosestBlock(startKey)
|
||||||
const after = selection.collapseToStartOf(nextNode)
|
const startInline = startBlock.getFurthestInline(startKey)
|
||||||
|
const nextText = document.getNextText(startText.key)
|
||||||
|
let after
|
||||||
|
|
||||||
|
// If the selection is at the start of the highest inline child inside the
|
||||||
|
// block, the starting text node won't need to be split.
|
||||||
|
if (
|
||||||
|
(startOffset == 0) &&
|
||||||
|
(startText == startInline || startInline.getOffset(startText.key) == 0)
|
||||||
|
) {
|
||||||
|
after = selection.collapseToStartOf(startText)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, we'll need to move the selection forward one to account for the
|
||||||
|
// text node that was split.
|
||||||
|
else {
|
||||||
|
after = selection.collapseToStartOf(nextText)
|
||||||
|
}
|
||||||
|
|
||||||
return transform.moveTo(after)
|
return transform.moveTo(after)
|
||||||
}
|
}
|
||||||
|
@@ -4,12 +4,12 @@ import assert from 'assert'
|
|||||||
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 second = texts.get(1)
|
||||||
const range = selection.merge({
|
const range = selection.merge({
|
||||||
anchorKey: first.key,
|
anchorKey: second.key,
|
||||||
anchorOffset: 4,
|
anchorOffset: 0,
|
||||||
focusKey: first.key,
|
focusKey: second.key,
|
||||||
focusOffset: 4
|
focusOffset: 0
|
||||||
})
|
})
|
||||||
|
|
||||||
const next = state
|
const next = state
|
||||||
@@ -17,12 +17,6 @@ export default function (state) {
|
|||||||
.moveTo(range)
|
.moveTo(range)
|
||||||
.splitBlock()
|
.splitBlock()
|
||||||
.apply()
|
.apply()
|
||||||
.transform()
|
|
||||||
.deleteBackward()
|
|
||||||
.apply()
|
|
||||||
.transform()
|
|
||||||
.splitBlock()
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
const updated = next.document.getTexts().get(1)
|
const updated = next.document.getTexts().get(1)
|
||||||
|
|
@@ -12,8 +12,5 @@ nodes:
|
|||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
text: hyperlink
|
text: hyperlink
|
||||||
- kind: block
|
|
||||||
type: paragraph
|
|
||||||
nodes:
|
|
||||||
- kind: text
|
- kind: text
|
||||||
text: word
|
text: word
|
@@ -15,8 +15,5 @@ nodes:
|
|||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
text: hyperlink
|
text: hyperlink
|
||||||
- kind: block
|
|
||||||
type: paragraph
|
|
||||||
nodes:
|
|
||||||
- kind: text
|
- kind: text
|
||||||
text: word
|
text: word
|
Reference in New Issue
Block a user