fix: Improved guard on floating toolbar position calculation

This commit is contained in:
Tom Moor
2023-05-27 09:59:55 -04:00
parent ef7ae719a6
commit 5dab811c5f

View File

@@ -104,20 +104,24 @@ function usePosition({
const element = (table.node as HTMLElement).querySelector(
`tr > *:nth-child(${rect.left + 1})`
);
const bounds = (element as HTMLElement).getBoundingClientRect();
selectionBounds.top = bounds.top - 16;
selectionBounds.left = bounds.left;
selectionBounds.right = bounds.right;
if (element instanceof HTMLElement) {
const bounds = element.getBoundingClientRect();
selectionBounds.top = bounds.top - 16;
selectionBounds.left = bounds.left;
selectionBounds.right = bounds.right;
}
} else if (isRowSelection) {
const rect = selectedRect(view.state);
const table = view.domAtPos(rect.tableStart);
const element = (table.node as HTMLElement).querySelector(
`tr:nth-child(${rect.top + 1}) > *`
);
const bounds = (element as HTMLElement).getBoundingClientRect();
selectionBounds.top = bounds.top;
selectionBounds.left = bounds.left - 10;
selectionBounds.right = bounds.left - 10;
if (element instanceof HTMLElement) {
const bounds = element.getBoundingClientRect();
selectionBounds.top = bounds.top;
selectionBounds.left = bounds.left - 10;
selectionBounds.right = bounds.left - 10;
}
}
const isImageSelection =