Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop selection on mouseMove if the mouse button not pressed #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/lexical-playground/__tests__/utils/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ export async function dragMouse(
positionStart = 'middle',
positionEnd = 'middle',
mouseUp = true,
slow = false,
) {
let fromX = fromBoundingBox.x;
let fromY = fromBoundingBox.y;
Expand All @@ -635,6 +636,11 @@ export async function dragMouse(
toY += toBoundingBox.height;
}

if (slow) {
//simulate more than 1 mouse move event to replicate human slow dragging
await page.mouse.move((fromX + toX) / 2, (fromY + toY) / 2);
}

await page.mouse.move(toX, toY);

if (mouseUp) {
Expand Down Expand Up @@ -793,6 +799,10 @@ export async function selectCellsFromTableCords(
page,
await firstRowFirstColumnCell.boundingBox(),
await secondRowSecondCell.boundingBox(),
'middle',
'middle',
true,
true,
);
}

Expand Down
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
Loading