mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-01-19 14:27:07 +01:00
allow Editor.insertText to take all location types
This commit is contained in:
parent
b2d0255097
commit
00d0b36aa4
@ -333,15 +333,18 @@ export const TextTransforms = {
|
||||
editor: Editor,
|
||||
text: string,
|
||||
options: {
|
||||
at?: Point | Range
|
||||
at?: Location
|
||||
} = {}
|
||||
) {
|
||||
Editor.withoutNormalizing(editor, () => {
|
||||
const { selection } = editor
|
||||
let { at } = options
|
||||
let { at = editor.selection } = options
|
||||
|
||||
if (!at && selection) {
|
||||
at = selection
|
||||
if (!at) {
|
||||
return
|
||||
}
|
||||
|
||||
if (Path.isPath(at)) {
|
||||
at = Editor.range(editor, at)
|
||||
}
|
||||
|
||||
if (Range.isRange(at)) {
|
||||
@ -354,10 +357,12 @@ export const TextTransforms = {
|
||||
}
|
||||
}
|
||||
|
||||
if (Point.isPoint(at) && !Editor.match(editor, at.path, 'void')) {
|
||||
const { path, offset } = at
|
||||
editor.apply({ type: 'insert_text', path, offset, text })
|
||||
if (Editor.match(editor, at.path, 'void')) {
|
||||
return
|
||||
}
|
||||
|
||||
const { path, offset } = at
|
||||
editor.apply({ type: 'insert_text', path, offset, text })
|
||||
})
|
||||
},
|
||||
}
|
||||
|
20
packages/slate/test/transforms/insertText/path/text.js
Normal file
20
packages/slate/test/transforms/insertText/path/text.js
Normal file
@ -0,0 +1,20 @@
|
||||
/** @jsx jsx */
|
||||
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>word</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const run = editor => {
|
||||
Editor.insertText(editor, 'x', { at: [0, 0] })
|
||||
}
|
||||
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>x</block>
|
||||
</editor>
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user