From 914f32d7dd73f40e565dd89e23edace8885ea1ef Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Thu, 23 Feb 2023 13:05:29 +0500 Subject: [PATCH] core: only check doc.textBetween if other checks pass --- packages/core/src/extensions/keymap.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core/src/extensions/keymap.ts b/packages/core/src/extensions/keymap.ts index 4b4a7a21033..0e26d7fced4 100644 --- a/packages/core/src/extensions/keymap.ts +++ b/packages/core/src/extensions/keymap.ts @@ -99,9 +99,13 @@ export const Keymap = Extension.create({ const allFrom = Selection.atStart(oldState.doc).from const allEnd = Selection.atEnd(oldState.doc).to const allWasSelected = from === allFrom && to === allEnd - const isEmpty = newState.doc.textBetween(0, newState.doc.content.size, ' ', ' ').length === 0 - if (empty || !allWasSelected || !isEmpty) { + if (empty || !allWasSelected) { + return + } + + const isEmpty = newState.doc.textBetween(0, newState.doc.content.size, ' ', ' ').length === 0 + if (!isEmpty) { return }