From ed0bf3b6053280fea02e89bc40fdfd6202df8ad0 Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Thu, 3 Aug 2023 08:53:00 +0300 Subject: [PATCH] backspace event tests fixed --- src/components/modules/blockEvents.ts | 10 ++++++---- src/components/modules/caret.ts | 9 +++------ test/cypress/tests/modules/BlockEvents/Backspace.cy.ts | 3 ++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/modules/blockEvents.ts b/src/components/modules/blockEvents.ts index d60e5bd82..ee2d00c32 100644 --- a/src/components/modules/blockEvents.ts +++ b/src/components/modules/blockEvents.ts @@ -454,10 +454,12 @@ export default class BlockEvents extends Module { BlockManager .mergeBlocks(targetBlock, blockToMerge) .then(() => { - /** Restore caret position after merge */ - Caret.restoreCaret(targetBlock.pluginsContent as HTMLElement); - targetBlock.pluginsContent.normalize(); - Toolbar.close(); + window.requestAnimationFrame(() => { + /** Restore caret position after merge */ + Caret.restoreCaret(targetBlock.pluginsContent as HTMLElement); + targetBlock.pluginsContent.normalize(); + Toolbar.close(); + }); }); } diff --git a/src/components/modules/caret.ts b/src/components/modules/caret.ts index a13903e4d..2e870213e 100644 --- a/src/components/modules/caret.ts +++ b/src/components/modules/caret.ts @@ -503,13 +503,10 @@ export default class Caret extends Module { sel.expandToTag(shadowCaret as HTMLElement); - setTimeout(() => { - const newRange = document.createRange(); + const newRange = document.createRange(); - newRange.selectNode(shadowCaret); - newRange.extractContents(); - // eslint-disable-next-line @typescript-eslint/no-magic-numbers - }, 50); + newRange.selectNode(shadowCaret); + newRange.extractContents(); } /** diff --git a/test/cypress/tests/modules/BlockEvents/Backspace.cy.ts b/test/cypress/tests/modules/BlockEvents/Backspace.cy.ts index 640d15232..23aa2ee98 100644 --- a/test/cypress/tests/modules/BlockEvents/Backspace.cy.ts +++ b/test/cypress/tests/modules/BlockEvents/Backspace.cy.ts @@ -252,7 +252,8 @@ describe('Backspace keydown', function () { .last() .click() .type('{home}') // move caret to the beginning - .type('{backspace}'); + .type('{backspace}') + .wait(100); /** * Current Block has been removed