1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-13 18:53:59 +02:00

Hanging Selection paste in insertFragmentAtRange (#1742)

This commit is contained in:
Jinxuan Zhu
2018-04-27 17:02:56 -04:00
committed by Ian Storm Taylor
parent 2dd77c00f1
commit 9b39a89f20
2 changed files with 49 additions and 1 deletions

View File

@@ -671,7 +671,11 @@ Changes.insertFragmentAtRange = (change, range, fragment, options = {}) => {
// If the range is expanded, delete it first.
if (range.isExpanded) {
change.deleteAtRange(range, { normalize: false })
range = range.collapseToStart()
if (change.value.document.getDescendant(range.startKey)) {
range = range.collapseToStart()
} else {
range = range.collapseTo(range.endKey, 0)
}
}
// If the fragment is empty, there's nothing to do after deleting.

View File

@@ -0,0 +1,44 @@
/** @jsx h */
import h from '../../../helpers/h'
const fragment = (
<document>
<paragraph>fragment zero</paragraph>
<paragraph>fragment one</paragraph>
<paragraph>fragment two</paragraph>
</document>
)
export default function(change) {
change.insertFragment(fragment)
}
export const input = (
<value>
<document>
<paragraph>zero</paragraph>
<paragraph>
<anchor />one
</paragraph>
<quote>
<focus />two
</quote>
</document>
</value>
)
// The cursor position of insertFragment has some problems;
// If you submit PR to fixed cursor position restore in insertFragment;
// Please change this test as well
export const output = (
<value>
<document>
<paragraph>zero</paragraph>
<quote>fragment zero</quote>
<paragraph>fragment one</paragraph>
<paragraph>
<cursor />fragment twotwo
</paragraph>
</document>
</value>
)