1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-13 11:44:55 +01:00

Fix inserting text with hanging selection, issue #1189 (#1432)

This commit is contained in:
David Hrdlicka 2017-12-02 12:29:00 -08:00 committed by Ian Storm Taylor
parent b3324db24c
commit 8928363471
3 changed files with 50 additions and 5 deletions

View File

@ -867,12 +867,18 @@ Changes.insertTextAtRange = (change, range, text, marks, options = {}) => {
const { value } = change
const { document } = value
const { startKey, startOffset } = range
let key = startKey
let offset = startOffset
const parent = document.getParent(startKey)
if (parent.isVoid) return
if (range.isExpanded) {
change.deleteAtRange(range, { normalize: false })
// Update range start after delete
key = change.value.startKey
offset = change.value.startOffset
}
// PERF: Unless specified, don't normalize if only inserting text.
@ -880,7 +886,7 @@ Changes.insertTextAtRange = (change, range, text, marks, options = {}) => {
normalize = range.isExpanded
}
change.insertTextByKey(startKey, startOffset, text, marks, { normalize })
change.insertTextByKey(key, offset, text, marks, { normalize })
}
/**

View File

@ -0,0 +1,33 @@
/** @jsx h */
import h from '../../../helpers/h'
export default function (change) {
change.insertText('a')
}
export const input = (
<value>
<document>
<paragraph>
<anchor />one
</paragraph>
<paragraph>
two
</paragraph>
<quote>
<focus />three
</quote>
</document>
</value>
)
export const output = (
<value>
<document>
<quote>
a<cursor />three
</quote>
</document>
</value>
)

View File

@ -3,14 +3,18 @@
import h from '../../../helpers/h'
export default function (change) {
change.delete()
change.insertText('a')
}
export const input = (
<value>
<document>
<quote><anchor />one</quote>
<paragraph><focus />two</paragraph>
<paragraph>
<anchor />one
</paragraph>
<quote>
<focus />two
</quote>
</document>
</value>
)
@ -18,7 +22,9 @@ export const input = (
export const output = (
<value>
<document>
<paragraph><cursor />two</paragraph>
<quote>
a<cursor />two
</quote>
</document>
</value>
)