Skip to content

Commit d1fa8cc

Browse files
committed
Bug fixes, part 2.
1 parent 9049309 commit d1fa8cc

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

‎src/components/splitpanes/splitpanes.vue‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ const calculatePanesSizeFromDragPercentage = dragPercentage => {
245245
if (paneBeforeMaxReached || paneAfterMaxReached) {
246246
if (paneBeforeMaxReached) {
247247
paneBefore.size = paneBefore.max
248-
paneAfter.size = Math.max(100 - paneBefore.max - sums.prevPanesSize - sums.nextPanesSize, 0)
248+
paneAfter.size = Math.min(Math.max(100 - paneBefore.max - sums.prevPanesSize - sums.nextPanesSize, paneAfter.min), paneAfter.max)
249249
}
250250
else {
251-
paneBefore.size = Math.max(100 - paneAfter.max - sums.prevPanesSize - sumNextPanesSize(splitterIndex + 1), 0)
251+
paneBefore.size = Math.min(Math.max(100 - paneAfter.max - sums.prevPanesSize - sumNextPanesSize(splitterIndex + 1), paneBefore.min), paneBefore.max)
252252
paneAfter.size = paneAfter.max
253253
}
254254
return
@@ -325,8 +325,8 @@ const doPushOtherPanes = (sums, dragPercentage) => {
325325
if (panesToResize[1] === undefined) {
326326
sums.nextReachedMinPanes = 0
327327
panes.value.forEach((pane, i) => {
328-
// If pushing a n+2 or more pane, from splitter, then make sure all in between is at min size.
329-
if (i < panesCount.value - 1 && i >= splitterIndex + 1) {
328+
// Set ALL next panes (including the last one) to min so sumNextPanesSize is accurate.
329+
if (i >= splitterIndex + 1) {
330330
pane.size = pane.min
331331
sums.nextReachedMinPanes += pane.min
332332
}
@@ -533,15 +533,14 @@ const initialPanesSizing = () => {
533533
}
534534
535535
const equalizeAfterAddOrRemove = ({ addedPane, removedPane } = {}) => {
536-
let equalSpace = 100 / panesCount.value
536+
// Distribute space only among panes without an explicit givenSize.
537+
const totalGivenSize = panes.value.reduce((sum, p) => sum + (p.givenSize !== null ? p.givenSize : 0), 0)
538+
const freeCount = panes.value.filter(p => p.givenSize === null).length
539+
let equalSpace = freeCount > 0 ? (100 - totalGivenSize) / freeCount : 0
537540
let leftToAllocate = 0
538541
const ungrowable = []
539542
const unshrinkable = []
540543
541-
if ((addedPane?.givenSize ?? null) !== null) {
542-
equalSpace = (100 - addedPane.givenSize) / (panesCount.value - 1)
543-
}
544-
545544
// Check if pre-allocated space is 100%.
546545
for (const pane of panes.value) {
547546
leftToAllocate -= pane.size
@@ -552,8 +551,8 @@ const equalizeAfterAddOrRemove = ({ addedPane, removedPane } = {}) => {
552551
if (Math.abs(leftToAllocate) < 0.1) return // Ok.
553552
554553
for (const pane of panes.value) {
555-
const addedPaneHasGivenSize = addedPane != null && addedPane.givenSize !== null && addedPane.id === pane.id
556-
if (!addedPaneHasGivenSize) pane.size = Math.max(Math.min(equalSpace, pane.max), pane.min)
554+
// Preserve the size of any pane that has an explicit givenSize (not just the newly added one).
555+
if (pane.givenSize === null) pane.size = Math.max(Math.min(equalSpace, pane.max), pane.min)
557556
558557
leftToAllocate -= pane.size
559558
if (pane.size >= pane.max) ungrowable.push(pane.id)

0 commit comments

Comments
 (0)