From e922d7f325cf63ab46cce1cacd76d2fc1ef1a9be Mon Sep 17 00:00:00 2001 From: weidenhoefer Date: Wed, 2 Oct 2024 09:43:45 +0200 Subject: [PATCH] Take padding into account when calculating lineheight The helper function getLineHeight calculates the height of a contextmenu entry by mocking two entries and divide the height of the container by two. But this does not take the padding of the container into account. Padding must be substracted from the offsetHeight. --- src/helpers/dom.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/helpers/dom.ts b/src/helpers/dom.ts index a3e4a98..fa41771 100644 --- a/src/helpers/dom.ts +++ b/src/helpers/dom.ts @@ -34,7 +34,11 @@ export function getLineHeight(container: HTMLDivElement): number { cloned.append(element2); container.parentNode?.append(cloned); - const height = cloned.offsetHeight / 2; + const clonedStyle = window.getComputedStyle(cloned); + const paddingTop = Number.parseInt(clonedStyle.paddingTop, 10); + const paddingBottom = Number.parseInt(clonedStyle.paddingBottom, 10); + + const height = (cloned.offsetHeight - (paddingTop + paddingBottom)) / 2; container.parentNode?.removeChild(cloned);