From 8f85b7f8228935556e8593eed4b65b2d0067b0e9 Mon Sep 17 00:00:00 2001 From: Buzurgmehr Arjmandi Date: Sat, 20 Jun 2020 00:39:11 +0300 Subject: [PATCH] fix: Collapsed panel no longer grows when not pushed by a sibling panel --- .../hooks/callbacks/useGetMovedSizes.ts | 30 +++++++++++++++++-- .../SplitPane/hooks/useSplitPaneResize.ts | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/components/SplitPane/hooks/callbacks/useGetMovedSizes.ts b/src/components/SplitPane/hooks/callbacks/useGetMovedSizes.ts index 3baeed0..d4da2a7 100644 --- a/src/components/SplitPane/hooks/callbacks/useGetMovedSizes.ts +++ b/src/components/SplitPane/hooks/callbacks/useGetMovedSizes.ts @@ -8,28 +8,52 @@ export function useGetMovedSizes({ isLtr, minSizes, collapsedIndices, + isReversed, collapsedSize, }: { sizes: number[]; isLtr: boolean; minSizes: number[]; collapsedIndices: number[]; + isReversed: boolean; collapsedSize: number; }) { return useCallback( (dragState: DragState | null): number[] => { if (!dragState) return originalSizes; const sizes = [...originalSizes]; + const index = dragState.extraState.index; + const offset = isLtr ? dragState.offset : -dragState.offset; moveSizes({ sizes: sizes, - index: dragState.extraState.index, - offset: isLtr ? dragState.offset : -dragState.offset, + index, + offset, minSizes, collapsedIndices, collapsedSize, }); + // must move all previously collapsed panes as well, slightly different to what happens when collapsing, though mostly identical + if (isReversed ? offset > 0 : offset < 0) { + for ( + let i = isReversed ? index : index + 1; + isReversed ? i > 0 : i < sizes.length - 1; + isReversed ? i-- : i++ + ) { + if (collapsedIndices.includes(i)) { + moveSizes({ + sizes, + index: isReversed ? i - 1 : i, + offset, + minSizes, + collapsedIndices, + collapsedSize, + }); + } + } + } + return sizes; }, - [collapsedIndices, collapsedSize, isLtr, minSizes, originalSizes] + [collapsedIndices, collapsedSize, isLtr, isReversed, minSizes, originalSizes] ); } diff --git a/src/components/SplitPane/hooks/useSplitPaneResize.ts b/src/components/SplitPane/hooks/useSplitPaneResize.ts index 449cad6..004929c 100644 --- a/src/components/SplitPane/hooks/useSplitPaneResize.ts +++ b/src/components/SplitPane/hooks/useSplitPaneResize.ts @@ -94,6 +94,7 @@ export function useSplitPaneResize(options: SplitPaneResizeOptions): SplitPaneRe isLtr, collapsedSize, collapsedIndices, + isReversed, }); const getCurrentPaneSizes = useGetCurrentPaneSizes({ childPanes, split }); const handleDragFinished = useHandleDragFinished({ getMovedSizes, children, hooks, setSizes });