1
0
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:
Ian Storm Taylor 2019-12-01 22:53:12 -05:00
parent b2d0255097
commit 00d0b36aa4
2 changed files with 33 additions and 8 deletions

View File

@ -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 })
})
},
}

View 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>
)