mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 14:11:35 +02:00
Fix splitBlock bug with hanging selection (#1747)
* Fix splitBlock bug with hanging selection * Restore marks
This commit is contained in:
committed by
Ian Storm Taylor
parent
6e6e9cf710
commit
bbbf73fc12
@@ -217,8 +217,12 @@ Changes.insertText = (change, text, marks) => {
|
|||||||
|
|
||||||
Changes.splitBlock = (change, depth = 1) => {
|
Changes.splitBlock = (change, depth = 1) => {
|
||||||
const { value } = change
|
const { value } = change
|
||||||
const { selection } = value
|
const { selection, document } = value
|
||||||
|
const marks = selection.marks || document.getInsertMarksAtRange(selection)
|
||||||
change.splitBlockAtRange(selection, depth).collapseToEnd()
|
change.splitBlockAtRange(selection, depth).collapseToEnd()
|
||||||
|
if (marks && marks.size !== 0) {
|
||||||
|
change.select({ marks })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -992,12 +992,7 @@ Changes.setInlineAtRange = (...args) => {
|
|||||||
Changes.splitBlockAtRange = (change, range, height = 1, options = {}) => {
|
Changes.splitBlockAtRange = (change, range, height = 1, options = {}) => {
|
||||||
const normalize = change.getFlag('normalize', options)
|
const normalize = change.getFlag('normalize', options)
|
||||||
|
|
||||||
if (range.isExpanded) {
|
const { startKey, startOffset, endOffset, endKey } = range
|
||||||
change.deleteAtRange(range, { normalize })
|
|
||||||
range = range.collapseToStart()
|
|
||||||
}
|
|
||||||
|
|
||||||
const { startKey, startOffset } = range
|
|
||||||
const { value } = change
|
const { value } = change
|
||||||
const { document } = value
|
const { document } = value
|
||||||
let node = document.assertDescendant(startKey)
|
let node = document.assertDescendant(startKey)
|
||||||
@@ -1010,7 +1005,19 @@ Changes.splitBlockAtRange = (change, range, height = 1, options = {}) => {
|
|||||||
h++
|
h++
|
||||||
}
|
}
|
||||||
|
|
||||||
change.splitDescendantsByKey(node.key, startKey, startOffset, { normalize })
|
change.splitDescendantsByKey(node.key, startKey, startOffset, {
|
||||||
|
normalize: normalize && range.isCollapsed,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (range.isExpanded) {
|
||||||
|
if (range.isBackward) range = range.flip()
|
||||||
|
const nextBlock = change.value.document.getNextBlock(node.key)
|
||||||
|
range = range.moveAnchorToStartOf(nextBlock)
|
||||||
|
if (startKey === endKey) {
|
||||||
|
range = range.moveFocusTo(range.anchorKey, endOffset - startOffset)
|
||||||
|
}
|
||||||
|
change.deleteAtRange(range, { normalize })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -0,0 +1,33 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export default function(change) {
|
||||||
|
change.splitBlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>zero</paragraph>
|
||||||
|
<paragraph>
|
||||||
|
<anchor />word
|
||||||
|
</paragraph>
|
||||||
|
<quote>
|
||||||
|
<focus />cat is cute
|
||||||
|
</quote>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>zero</paragraph>
|
||||||
|
<paragraph />
|
||||||
|
<quote>
|
||||||
|
<cursor />cat is cute
|
||||||
|
</quote>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
@@ -0,0 +1,38 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export default function(change) {
|
||||||
|
change
|
||||||
|
.addMark('italic')
|
||||||
|
.splitBlock()
|
||||||
|
.insertText('cat is cute')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>
|
||||||
|
<b>word</b>
|
||||||
|
<cursor />
|
||||||
|
</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>
|
||||||
|
<b>word</b>
|
||||||
|
<cursor />
|
||||||
|
</paragraph>
|
||||||
|
<paragraph>
|
||||||
|
<i>
|
||||||
|
<b>cat is cute</b>
|
||||||
|
</i>
|
||||||
|
<cursor />
|
||||||
|
</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
Reference in New Issue
Block a user