Skip to content

Commit

Permalink
backspace event tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
neSpecc committed Aug 3, 2023
1 parent 51654e2 commit ed0bf3b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 6 additions & 4 deletions src/components/modules/blockEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
}

Expand Down
9 changes: 3 additions & 6 deletions src/components/modules/caret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion test/cypress/tests/modules/BlockEvents/Backspace.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed0bf3b

Please sign in to comment.