Skip to content

Commit 3d6ac02

Browse files
fix: infinite re-rendering of actions inside inline toolbar
1 parent 99d33da commit 3d6ac02

File tree

1 file changed

+13
-0
lines changed
  • src/components/modules

1 file changed

+13
-0
lines changed

src/components/modules/ui.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ interface UINodes {
4141
* @property {Element} nodes.redactor - <ce-redactor>
4242
*/
4343
export default class UI extends Module<UINodes> {
44+
/**
45+
* This is the cached selection anchor element in order to check if the selection
46+
* has actually changed and prevent inifinite firing and handling of the selectionchange event.
47+
*/
48+
private prevSelectionAnchorElement: Element | null = null;
49+
4450
/**
4551
* Editor.js UI CSS class names
4652
*
@@ -787,6 +793,7 @@ export default class UI extends Module<UINodes> {
787793
}
788794
}
789795

796+
790797
/**
791798
* Handle selection changes on mobile devices
792799
* Uses for showing the Inline Toolbar
@@ -795,6 +802,12 @@ export default class UI extends Module<UINodes> {
795802
const { CrossBlockSelection, BlockSelection } = this.Editor;
796803
const focusedElement = Selection.anchorElement;
797804

805+
if (this.prevSelectionAnchorElement == focusedElement) {
806+
return;
807+
}
808+
809+
this.prevSelectionAnchorElement = focusedElement;
810+
798811
if (CrossBlockSelection.isCrossBlockSelectionStarted) {
799812
// Removes all ranges when any Block is selected
800813
if (BlockSelection.anyBlockSelected) {

0 commit comments

Comments
 (0)