1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 02:49:56 +02:00

Merge pull request #436 from arekkas/case-432

Added failing test case for inlines causing selection issue #432
This commit is contained in:
Ian Storm Taylor
2016-11-18 11:43:17 -08:00
committed by GitHub
4 changed files with 86 additions and 4 deletions

View File

@@ -312,10 +312,28 @@ 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) &&
(startBlock.text != '') &&
(!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)
}

View File

@@ -0,0 +1,29 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const second = texts.get(1)
const range = selection.merge({
anchorKey: second.key,
anchorOffset: 0,
focusKey: second.key,
focusOffset: 0
})
const next = state
.transform()
.moveTo(range)
.splitBlock()
.apply()
const updated = next.document.getTexts().get(1)
assert.deepEqual(
next.selection.toJS(),
range.collapseToStartOf(updated).toJS()
)
return next
}

View File

@@ -0,0 +1,16 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: word
- kind: inline
type: link
data:
href: 'website.com'
nodes:
- kind: text
text: hyperlink
- kind: text
text: word

View File

@@ -0,0 +1,19 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: word
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
data:
href: 'website.com'
nodes:
- kind: text
text: hyperlink
- kind: text
text: word