mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-01 19:22:35 +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:
@@ -312,10 +312,28 @@ 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) &&
|
||||||
|
(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)
|
return transform.moveTo(after)
|
||||||
}
|
}
|
||||||
|
@@ -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
|
||||||
|
}
|
@@ -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
|
@@ -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
|
Reference in New Issue
Block a user