diff --git a/lib/plugins/core.js b/lib/plugins/core.js index de0142b01..025cc984e 100644 --- a/lib/plugins/core.js +++ b/lib/plugins/core.js @@ -110,10 +110,9 @@ function Plugin(options = {}) { /** * The core `onBeforeInput` handler. * - * If the current selection is expanded, we have to re-render. * - * If the next state resolves a new list of decorations for any of its text - * nodes, we have to re-render. + * + * * * Otherwise, we can allow the default, native text insertion, avoiding a * re-render for improved performance. @@ -128,17 +127,32 @@ function Plugin(options = {}) { const transform = state.transform().insertText(e.data) const synthetic = transform.apply() const resolved = editor.resolveState(synthetic) + let isNative = true - const isSynthenic = ( - state.isExpanded || - !resolved.equals(synthetic) - ) + // If the current selection is expanded, we have to re-render. + if (state.isExpanded) { + isNative = false + } - if (isSynthenic) e.preventDefault() + // If the current node was empty, we have to re-render so that any empty + // placeholder logic will be updated. + if (state.startText.text == '') { + isNative = false + } - return isSynthenic - ? synthetic - : transform.apply({ isNative: true }) + // If the next state resolves a new list of decorations for any of its + // text nodes, we have to re-render. + else if (!resolved.equals(synthetic)) { + isNative = false + } + + // Update the state with the proper `isNative`. + state = isNative + ? transform.apply({ isNative }) + : synthetic + + if (!isNative) e.preventDefault() + return state }, /**