diff --git a/src/transforms/at-current-range.js b/src/transforms/at-current-range.js index 6f570f91a..091a83fa2 100644 --- a/src/transforms/at-current-range.js +++ b/src/transforms/at-current-range.js @@ -221,29 +221,10 @@ export function insertInline(transform, inline) { export function insertText(transform, text, marks) { const { state } = transform - const { document, selection } = state - const { startKey } = selection - const isVoid = document.hasVoidParent(startKey) - let after - - if (isVoid) { - after = selection - } - - else if (selection.isExpanded) { - after = selection.collapseToStart().moveForward(text.length) - } - - else { - after = selection.moveForward(text.length) - } - + const { selection } = state marks = marks || selection.marks - - transform - .unsetSelection() - .insertTextAtRange(selection, text, marks) - .moveTo(after) + transform.insertTextAtRange(selection, text, marks) + transform.unsetMarks() } /** diff --git a/src/transforms/index.js b/src/transforms/index.js index a1c69037d..3a0d165ae 100644 --- a/src/transforms/index.js +++ b/src/transforms/index.js @@ -129,6 +129,7 @@ import { moveTo, moveToOffsets, moveToRangeOf, + unsetMarks, unsetSelection, } from './on-selection' @@ -281,6 +282,7 @@ export default { moveTo, moveToOffsets, moveToRangeOf, + unsetMarks, unsetSelection, /** diff --git a/src/transforms/on-selection.js b/src/transforms/on-selection.js index 7f2957399..639522b24 100644 --- a/src/transforms/on-selection.js +++ b/src/transforms/on-selection.js @@ -374,6 +374,16 @@ export function moveToRangeOf(transform, start, end) { transform.setSelectionOperation(sel) } +/** + * Unset the selection's marks. + * + * @param {Transform} transform + */ + +export function unsetMarks(transform) { + transform.setSelectionOperation({ marks: null }) +} + /** * Unset the selection, removing an association to a node. *