From b0e1d5e7fa7b1ff100e72aa61581b7fe788686a2 Mon Sep 17 00:00:00 2001 From: Ajay Date: Wed, 14 Sep 2022 02:58:22 -0400 Subject: [PATCH] Fix seek bar sometimes becoming empty when one seek section is completely filled --- src/js-components/previewBar.ts | 35 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts index 997befa9..a845b8f8 100644 --- a/src/js-components/previewBar.ts +++ b/src/js-components/previewBar.ts @@ -584,6 +584,7 @@ class PreviewBar { { left: number, scale: number } { const sections = currentElement.parentElement.parentElement.parentElement.children; let currentWidth = 0; + let lastWidth = 0; let left = 0; let leftPosition = 0; @@ -591,6 +592,7 @@ class PreviewBar { let scale = null; let scalePosition = 0; let scaleWidth = 0; + let lastScalePosition = 0; for (let i = 0; i < sections.length; i++) { const section = sections[i] as HTMLElement; @@ -610,24 +612,33 @@ class PreviewBar { const transformMatch = checkElement.style.transform.match(/scaleX\(([0-9.]+?)\)/); if (transformMatch) { const transformScale = parseFloat(transformMatch[1]); - if (i === sections.length - 1 || (transformScale < 1 && transformScale + checkLeft / currentSectionWidthNoMargin < 0.99999)) { - scale = transformScale; - scaleWidth = currentSectionWidthNoMargin; + const endPosition = transformScale + checkLeft / currentSectionWidthNoMargin; - if (transformScale > 0) { - // reached the end of this section for sure, since the scale is now between 0 and 1 - // if the scale is always zero, then it will go through all sections but still return 0 + if (lastScalePosition > 0.99999 && endPosition === 0) { + // Last one was an end section that was fully filled + scalePosition = currentWidth - lastWidth; + break; + } - scalePosition = currentWidth; - if (checkLeft !== 0) { - scalePosition += left; - } - break; + lastScalePosition = endPosition; + + scale = transformScale; + scaleWidth = currentSectionWidthNoMargin; + + if ((i === sections.length - 1 || endPosition < 0.99999) && endPosition > 0) { + // reached the end of this section for sure + // if the scale is always zero, then it will go through all sections but still return 0 + + scalePosition = currentWidth; + if (checkLeft !== 0) { + scalePosition += left; } + break; } } - currentWidth += currentSectionWidth; + lastWidth = currentSectionWidth; + currentWidth += lastWidth; } return {