diff --git a/packages/core/src/inputRules/nodeInputRule.ts b/packages/core/src/inputRules/nodeInputRule.ts index b6b3158f..bbfa6485 100644 --- a/packages/core/src/inputRules/nodeInputRule.ts +++ b/packages/core/src/inputRules/nodeInputRule.ts @@ -8,8 +8,24 @@ export default function (regexp: RegExp, type: NodeType, getAttributes?: (match: : getAttributes const { tr } = state - if (match[0]) { - tr.replaceWith(start - 1, end, type.create(attributes)) + if (match[1]) { + const offset = match[0].lastIndexOf(match[1]) + let matchStart = start + offset + if (matchStart > end) { + matchStart = end + } + else { + end = matchStart + match[1].length + } + + // insert last typed character + const lastChar = match[0][match[0].length - 1] + tr.insertText(lastChar, start + match[0].length - 1) + + // insert node from input rule + tr.replaceWith(matchStart, end, type.create(attributes)) + } else if (match[0]) { + tr.replaceWith(start, end, type.create(attributes)) } return tr