Take padding into account when converting mouse coord to cell

Part of microsoft/vscode#148061
This commit is contained in:
Daniel Imms
2022-05-23 06:49:52 -07:00
parent 55b420b016
commit 8b53b8c255
+7 -1
View File
@@ -5,7 +5,13 @@
export function getCoordsRelativeToElement(event: {clientX: number, clientY: number}, element: HTMLElement): [number, number] {
const rect = element.getBoundingClientRect();
return [event.clientX - rect.left, event.clientY - rect.top];
const elementStyle = window.getComputedStyle(element);
const leftPadding = parseInt(elementStyle.getPropertyValue('padding-left'));
const topPadding = parseInt(elementStyle.getPropertyValue('padding-top'));
return [
event.clientX - rect.left - leftPadding,
event.clientY - rect.top - topPadding
];
}
/**