Skip to content

Commit

Permalink
Stop selection on mouseMove if the mouse button not pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
areznik10 committed Apr 26, 2024
1 parent db7b242 commit c90a41d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/lexical-table/src/LexicalTableSelectionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export const getDOMSelection = (
): Selection | null =>
CAN_USE_DOM ? (targetWindow || window).getSelection() : null;

const isMouseDownOnEvent = (event: MouseEvent) => {
return (event.buttons & 1) === 1;
};

export function applyTableHandlers(
tableNode: TableNode,
tableElement: HTMLTableElementWithWithTableSelectionState,
Expand Down Expand Up @@ -104,6 +108,12 @@ export function applyTableHandlers(
const onMouseMove = (moveEvent: MouseEvent) => {
// delaying mousemove handler to allow selectionchange handler from LexicalEvents.ts to be executed first
setTimeout(() => {
if (!isMouseDownOnEvent(moveEvent) && tableObserver.isSelecting) {
tableObserver.isSelecting = false;
editorWindow.removeEventListener('mouseup', onMouseUp);
editorWindow.removeEventListener('mousemove', onMouseMove);
return;
}
const focusCell = getDOMCellFromTarget(moveEvent.target as Node);
if (
focusCell !== null &&
Expand Down

0 comments on commit c90a41d

Please sign in to comment.