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 { value } = change
|
||||||
const { document } = value
|
const { document } = value
|
||||||
const { startKey, startOffset } = range
|
const { startKey, startOffset } = range
|
||||||
|
let key = startKey
|
||||||
|
let offset = startOffset
|
||||||
const parent = document.getParent(startKey)
|
const parent = document.getParent(startKey)
|
||||||
|
|
||||||
if (parent.isVoid) return
|
if (parent.isVoid) return
|
||||||
|
|
||||||
if (range.isExpanded) {
|
if (range.isExpanded) {
|
||||||
change.deleteAtRange(range, { normalize: false })
|
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.
|
// PERF: Unless specified, don't normalize if only inserting text.
|
||||||
@ -880,7 +886,7 @@ Changes.insertTextAtRange = (change, range, text, marks, options = {}) => {
|
|||||||
normalize = range.isExpanded
|
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'
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
export default function (change) {
|
export default function (change) {
|
||||||
change.delete()
|
change.insertText('a')
|
||||||
}
|
}
|
||||||
|
|
||||||
export const input = (
|
export const input = (
|
||||||
<value>
|
<value>
|
||||||
<document>
|
<document>
|
||||||
<quote><anchor />one</quote>
|
<paragraph>
|
||||||
<paragraph><focus />two</paragraph>
|
<anchor />one
|
||||||
|
</paragraph>
|
||||||
|
<quote>
|
||||||
|
<focus />two
|
||||||
|
</quote>
|
||||||
</document>
|
</document>
|
||||||
</value>
|
</value>
|
||||||
)
|
)
|
||||||
@ -18,7 +22,9 @@ export const input = (
|
|||||||
export const output = (
|
export const output = (
|
||||||
<value>
|
<value>
|
||||||
<document>
|
<document>
|
||||||
<paragraph><cursor />two</paragraph>
|
<quote>
|
||||||
|
a<cursor />two
|
||||||
|
</quote>
|
||||||
</document>
|
</document>
|
||||||
</value>
|
</value>
|
||||||
)
|
)
|
Loading…
x
Reference in New Issue
Block a user