Skip to content

Commit

Permalink
fix: fix panel pushing bug introduct in 0.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
orefalo committed Sep 24, 2024
1 parent 1a21d05 commit b4c71f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
61 changes: 33 additions & 28 deletions src/lib/Splitpanes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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 => {
Expand All @@ -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 };
Expand Down

0 comments on commit b4c71f8

Please sign in to comment.