mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-13 11:44:55 +01:00
parent
b3324db24c
commit
8928363471
@ -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 })
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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>
|
||||
)
|
@ -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>
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user