From 5251d85fef82bb96f8fa82545cbc1943c2320e59 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 28 Aug 2023 12:05:56 +0200 Subject: [PATCH] Changes for #1234 --- vendors/squire/build/squire-raw.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/vendors/squire/build/squire-raw.js b/vendors/squire/build/squire-raw.js index 6f97b0c73..a12152ce4 100644 --- a/vendors/squire/build/squire-raw.js +++ b/vendors/squire/build/squire-raw.js @@ -1800,7 +1800,8 @@ function onKey(event) { let key = event.key.toLowerCase(), modifiers = '', - range = this.getSelection(); + range = this.getSelection(), + root = this._root; // We need to apply the backspace/delete handlers regardless of // control key modifiers. @@ -1819,13 +1820,13 @@ function onKey(event) { // Record undo checkpoint. this.saveUndoState(range); // Delete the selection - deleteContentsOfRange(range, this._root); + deleteContentsOfRange(range, root); this._ensureBottomLine(); this.setSelection(range); this._updatePath(range, true); } else if (range.collapsed - && range.startContainer === this._root - && this._root.children.length > 0) { + && range.startContainer === root + && root.children.length > 0) { // Under certain conditions, cursor/range can be positioned directly // under this._root (not wrapped) and when this happens, an inline(TEXT) @@ -1836,25 +1837,20 @@ function onKey(event) { // Therefor, we try to detect this case here and wrap the cursor/range // before the text is inserted. - const nextElement = this._root.children[range.startOffset]; - if (nextElement.tagName === blockTag - && nextElement.children.length === 1 - && nextElement.children[0].tagName === 'BR') { - // this is a suitable '
' wrapper, move selection to here - range = createRange(nextElement, 0); - } else { + const nextElement = root.children[range.startOffset]; + if (nextElement && !isBlock(nextElement)) { // create a new wrapper - range = createRange(this._root.insertBefore( + range = createRange(root.insertBefore( this.createDefaultBlock(), nextElement ), 0); if (nextElement.tagName === 'BR') { // delete it because a new