diff --git a/packages/slate/src/create-editor.ts b/packages/slate/src/create-editor.ts index 6075bae0f..1a5ee471b 100755 --- a/packages/slate/src/create-editor.ts +++ b/packages/slate/src/create-editor.ts @@ -128,7 +128,26 @@ export const createEditor = (): Editor => { } case 'insert_text': { - Editor.insertText(editor, command.text) + if (selection) { + const { anchor } = selection + + // If the cursor is at the end of an inline, move it outside + // of the inline before inserting + if (Range.isCollapsed(selection)) { + const inline = Editor.match(editor, anchor, 'inline') + + if (inline) { + const [, inlinePath] = inline + + if (Editor.isEnd(editor, anchor, inlinePath)) { + const point = Editor.after(editor, inlinePath)! + Editor.setSelection(editor, { anchor: point, focus: point }) + } + } + } + + Editor.insertText(editor, command.text) + } break } } diff --git a/packages/slate/src/interfaces/editor/transforms/text.ts b/packages/slate/src/interfaces/editor/transforms/text.ts index 1074b7007..8bb5ee2a3 100644 --- a/packages/slate/src/interfaces/editor/transforms/text.ts +++ b/packages/slate/src/interfaces/editor/transforms/text.ts @@ -392,6 +392,7 @@ export const TextTransforms = { const pointRef = Editor.pointRef(editor, end) Editor.delete(editor, { at, voids }) at = pointRef.unref()! + Editor.setSelection(editor, { anchor: at, focus: at }) } } diff --git a/packages/slate/test/transforms/insertText/selection/inline-end.js b/packages/slate/test/transforms/insertText/selection/inline-end.js new file mode 100644 index 000000000..64e65638c --- /dev/null +++ b/packages/slate/test/transforms/insertText/selection/inline-end.js @@ -0,0 +1,31 @@ +/** @jsx jsx */ + +import { jsx } from '../../..' + +export const run = editor => { + editor.exec({ type: 'insert_text', text: 'four' }) +} + +export const input = ( + + + one + + two + + + three + + +) + +export const output = ( + + + one + two + fourthree + + + +)