From b4c71f8a22c512d77eed0ad533f7b7989f69db61 Mon Sep 17 00:00:00 2001 From: Olivier Refalo Date: Tue, 24 Sep 2024 18:49:44 +0400 Subject: [PATCH] fix: fix panel pushing bug introduct in 0.8.3 --- package.json | 2 +- src/lib/Splitpanes.svelte | 61 +++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 751f3fca..590c32e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte-splitpanes", - "version": "8.0.5", + "version": "8.0.5", "private": false, "description": "A full featured resizable pane layout splitter, ported from vue-splitpanes and enhanced", "keywords": [ diff --git a/src/lib/Splitpanes.svelte b/src/lib/Splitpanes.svelte index 706f7489..55a7bc2a 100644 --- a/src/lib/Splitpanes.svelte +++ b/src/lib/Splitpanes.svelte @@ -758,27 +758,20 @@ function doPushOtherPanes(sums: Sums, dragPercentage: number) { const splitterIndex = activeSplitter - 1; - let paneBeforeIndex = splitterIndex; - let paneAfterIndex = splitterIndex + 1; + let paneBeforeIndex: number | undefined = splitterIndex; + let paneAfterIndex: number | undefined = splitterIndex + 1; // Pushing Down. // Going smaller than the current pane min size: take the previous expanded pane. if (dragPercentage < sums.prevPanesSize + panes[paneBeforeIndex].min()) { - paneBeforeIndex = findPrevExpandedPane(splitterIndex)?.index || 0; + paneBeforeIndex = findPrevExpandedPane(splitterIndex)?.index; sums.prevReachedMinPanes = 0; - // If pushing a n-2 or less pane, from splitter, then make sure all in between is at min size. - if (paneBeforeIndex < splitterIndex) { - forEachPartial(panes, paneBeforeIndex + 1, splitterIndex + 1, pane => { - pane.setSz(pane.min()); - sums.prevReachedMinPanes += pane.min(); - }); - } - sums.prevPanesSize = sumPrevPanesSize(paneBeforeIndex); - // If nothing else to push down, cancel dragging. - if (paneBeforeIndex == null) { - sums.prevReachedMinPanes = 0; + + if (paneBeforeIndex === undefined) { + // If nothing else to push down, cancel dragging. + sums.prevPanesSize = 0; panes[0].setSz(panes[0].min()); - forEachPartial(panes, 1, splitterIndex + 1, pane => { + forEachPartial(panes, 1, splitterIndex + 1, (pane: IPane) => { pane.setSz(pane.min()); sums.prevReachedMinPanes += pane.min(); }); @@ -787,26 +780,29 @@ 100 - sums.prevReachedMinPanes - panes[0].min() - sums.prevPanesSize - sums.nextPanesSize ); return null; + } else { + // If pushing a n-2 or less pane, from splitter, then make sure all in between is at min size. + if (paneBeforeIndex < splitterIndex) { + forEachPartial(panes, paneBeforeIndex + 1, splitterIndex + 1, (pane: IPane) => { + pane.setSz(pane.min()); + sums.prevReachedMinPanes += pane.min(); + }); + } + sums.prevPanesSize = sumPrevPanesSize(paneBeforeIndex); } } // Pushing Up. // Pushing up beyond min size is reached: take the next expanded pane. if (dragPercentage > 100 - sums.nextPanesSize - panes[paneAfterIndex].min()) { - paneAfterIndex = findNextExpandedPane(splitterIndex)?.index || 0; + paneAfterIndex = findNextExpandedPane(splitterIndex)?.index; + if (paneBeforeIndex === undefined) console.log('Yep undefined paneAfterIndex'); sums.nextReachedMinPanes = 0; - // If pushing a n+2 or more pane, from splitter, then make sure all in between is at min size. - if (paneAfterIndex > splitterIndex + 1) { - forEachPartial(panes, splitterIndex + 1, paneAfterIndex, pane => { - pane.setSz(pane.min()); - sums.nextReachedMinPanes += pane.min(); - }); - } - sums.nextPanesSize = sumNextPanesSize(paneAfterIndex); - // If nothing else to push up, cancel dragging. - const panesCount = panes.length; - if (paneAfterIndex == null) { - sums.nextReachedMinPanes = 0; + if (paneAfterIndex === undefined) { + // If nothing else to push up, cancel dragging. + sums.nextPanesSize = 0; + + const panesCount = panes.length; panes[panesCount - 1].setSz(panes[panesCount - 1].min()); forEachPartial(panes, splitterIndex + 1, panesCount - 1, pane => { @@ -822,6 +818,15 @@ sums.nextPanesSize ); return null; + } else { + // If pushing a n+2 or more pane, from splitter, then make sure all in between is at min size. + if (paneAfterIndex > splitterIndex + 1) { + forEachPartial(panes, splitterIndex + 1, paneAfterIndex, (pane: IPane) => { + pane.setSz(pane.min()); + sums.nextReachedMinPanes += pane.min(); + }); + } + sums.nextPanesSize = sumNextPanesSize(paneAfterIndex); } } return { sums, paneBeforeIndex, paneAfterIndex };