Skip to content

Commit

Permalink
Don't use global window (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-cheloshkin authored Feb 29, 2024
1 parent f438926 commit 07771a8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/columnresizing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ function handleMouseDown(
event: MouseEvent,
cellMinWidth: number,
): boolean {
const win = view.dom.ownerDocument.defaultView ?? window;

const pluginState = columnResizingPluginKey.getState(view.state);
if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging)
return false;
Expand All @@ -189,8 +191,8 @@ function handleMouseDown(
);

function finish(event: MouseEvent) {
window.removeEventListener('mouseup', finish);
window.removeEventListener('mousemove', move);
win.removeEventListener('mouseup', finish);
win.removeEventListener('mousemove', move);
const pluginState = columnResizingPluginKey.getState(view.state);
if (pluginState?.dragging) {
updateColumnWidth(
Expand All @@ -214,8 +216,8 @@ function handleMouseDown(
}
}

window.addEventListener('mouseup', finish);
window.addEventListener('mousemove', move);
win.addEventListener('mouseup', finish);
win.addEventListener('mousemove', move);
event.preventDefault();
return true;
}
Expand Down

0 comments on commit 07771a8

Please sign in to comment.