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

fix: Table handles hide when selection is active #1111

Merged
merged 2 commits into from
Sep 30, 2024
Merged
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
26 changes: 26 additions & 0 deletions packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export class TableHandlesView<

public menuFrozen = false;

public mouseState: "up" | "down" | "selecting" = "up";

public prevWasEditable: boolean | null = null;

constructor(
Expand All @@ -127,6 +129,8 @@ export class TableHandlesView<
};

pmView.dom.addEventListener("mousemove", this.mouseMoveHandler);
pmView.dom.addEventListener("mousedown", this.viewMousedownHandler);
pmView.dom.addEventListener("mouseup", this.viewMouseupHandler);

pmView.root.addEventListener(
"dragover",
Expand All @@ -140,11 +144,33 @@ export class TableHandlesView<
pmView.root.addEventListener("scroll", this.scrollHandler, true);
}

viewMousedownHandler = () => {
this.mouseState = "down";
};

viewMouseupHandler = (event: MouseEvent) => {
this.mouseState = "up";
this.mouseMoveHandler(event);
};

mouseMoveHandler = (event: MouseEvent) => {
if (this.menuFrozen) {
return;
}

if (this.mouseState === "down") {
this.mouseState = "selecting";

if (this.state?.show) {
this.state.show = false;
this.emitUpdate();
}
}

if (this.mouseState === "selecting") {
return;
}

const target = domCellAround(event.target as HTMLElement);

if (!target || !this.editor.isEditable) {
Expand Down
Loading