Skip to content

Commit

Permalink
Add setTimeout for mousemove handler (#5919)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderReznik authored Apr 19, 2024
1 parent 98b0537 commit 78bac6c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/lexical-table/src/LexicalTableSelectionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};
};
Expand Down

0 comments on commit 78bac6c

Please sign in to comment.