From 78bac6c57d0615e7070f6418fc845b8684af25c3 Mon Sep 17 00:00:00 2001 From: Alex Reznik Date: Fri, 19 Apr 2024 14:09:04 +0100 Subject: [PATCH] Add setTimeout for mousemove handler (#5919) --- .../src/LexicalTableSelectionHelpers.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/lexical-table/src/LexicalTableSelectionHelpers.ts b/packages/lexical-table/src/LexicalTableSelectionHelpers.ts index cf6db409f0b..ed443fc3f17 100644 --- a/packages/lexical-table/src/LexicalTableSelectionHelpers.ts +++ b/packages/lexical-table/src/LexicalTableSelectionHelpers.ts @@ -102,15 +102,18 @@ export function applyTableHandlers( }; const onMouseMove = (moveEvent: MouseEvent) => { - const focusCell = getDOMCellFromTarget(moveEvent.target as Node); - if ( - focusCell !== null && - (tableObserver.anchorX !== focusCell.x || - tableObserver.anchorY !== focusCell.y) - ) { - moveEvent.preventDefault(); - tableObserver.setFocusCellForSelection(focusCell); - } + // delaying mousemove handler to allow selectionchange handler from LexicalEvents.ts to be executed first + setTimeout(() => { + const focusCell = getDOMCellFromTarget(moveEvent.target as Node); + if ( + focusCell !== null && + (tableObserver.anchorX !== focusCell.x || + tableObserver.anchorY !== focusCell.y) + ) { + moveEvent.preventDefault(); + tableObserver.setFocusCellForSelection(focusCell); + } + }, 0); }; return {onMouseMove: onMouseMove, onMouseUp: onMouseUp}; };