mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-31 19:01:54 +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
|
||||
document = state.document
|
||||
|
||||
const { startKey } = selection
|
||||
const startNode = document.getDescendant(startKey)
|
||||
const nextNode = document.getNextText(startNode.key)
|
||||
const after = selection.collapseToStartOf(nextNode)
|
||||
const { startKey, startOffset } = selection
|
||||
const startText = document.getNode(startKey)
|
||||
const startBlock = document.getClosestBlock(startKey)
|
||||
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)
|
||||
}
|
||||
|
@@ -4,12 +4,12 @@ import assert from 'assert'
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const second = texts.get(1)
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 4,
|
||||
focusKey: first.key,
|
||||
focusOffset: 4
|
||||
anchorKey: second.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: second.key,
|
||||
focusOffset: 0
|
||||
})
|
||||
|
||||
const next = state
|
||||
@@ -17,12 +17,6 @@ export default function (state) {
|
||||
.moveTo(range)
|
||||
.splitBlock()
|
||||
.apply()
|
||||
.transform()
|
||||
.deleteBackward()
|
||||
.apply()
|
||||
.transform()
|
||||
.splitBlock()
|
||||
.apply()
|
||||
|
||||
const updated = next.document.getTexts().get(1)
|
||||
|
@@ -12,8 +12,5 @@ nodes:
|
||||
nodes:
|
||||
- kind: text
|
||||
text: hyperlink
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: word
|
||||
text: word
|
@@ -15,8 +15,5 @@ nodes:
|
||||
nodes:
|
||||
- kind: text
|
||||
text: hyperlink
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: word
|
Reference in New Issue
Block a user