@@ -13,6 +13,7 @@ import {
1313 nextGroupId ,
1414 paneRects ,
1515 repairLayout ,
16+ resetSplit ,
1617 resize ,
1718 resizeFromPointer ,
1819 singleGroup ,
@@ -354,6 +355,64 @@ describe('resize', () => {
354355 } )
355356} )
356357
358+ describe ( 'resetSplit' , ( ) => {
359+ it ( 'evens out an unequal pair' , ( ) => {
360+ const tree = split (
361+ 'row' ,
362+ [ group ( 'g0' , [ 'a' ] ) , group ( 'g1' , [ 'b' ] ) ] ,
363+ [ 0.7 , 0.3 ] ,
364+ )
365+ const next = resetSplit ( tree , [ ] , 0 ) as SplitNode
366+ expect ( next . sizes [ 0 ] ) . toBeCloseTo ( 0.5 , 10 )
367+ expect ( next . sizes [ 1 ] ) . toBeCloseTo ( 0.5 , 10 )
368+ expectWellFormed ( next )
369+ } )
370+
371+ it ( 'only touches the gutter pair, leaving the rest alone' , ( ) => {
372+ const tree = split (
373+ 'row' ,
374+ [ group ( 'g0' , [ 'a' ] ) , group ( 'g1' , [ 'b' ] ) , group ( 'g2' , [ 'c' ] ) ] ,
375+ [ 0.1 , 0.7 , 0.2 ] ,
376+ )
377+ const next = resetSplit ( tree , [ ] , 0 ) as SplitNode
378+ expect ( next . sizes [ 0 ] ) . toBeCloseTo ( 0.4 , 10 )
379+ expect ( next . sizes [ 1 ] ) . toBeCloseTo ( 0.4 , 10 )
380+ expect ( next . sizes [ 2 ] ) . toBeCloseTo ( 0.2 , 10 )
381+ expectWellFormed ( next )
382+ } )
383+
384+ it ( 'resets a nested split by path' , ( ) => {
385+ const tree = split ( 'row' , [
386+ group ( 'g0' , [ 'a' ] ) ,
387+ split ( 'col' , [ group ( 'g1' , [ 'b' ] ) , group ( 'g2' , [ 'c' ] ) ] , [ 0.8 , 0.2 ] ) ,
388+ ] )
389+ const next = resetSplit ( tree , [ 1 ] , 0 ) as SplitNode
390+ const inner = next . children [ 1 ] as SplitNode
391+ expect ( inner . sizes [ 0 ] ) . toBeCloseTo ( 0.5 , 10 )
392+ expect ( inner . sizes [ 1 ] ) . toBeCloseTo ( 0.5 , 10 )
393+ // The outer split is untouched.
394+ expect ( next . sizes [ 0 ] ) . toBeCloseTo ( 0.5 , 10 )
395+ expectWellFormed ( next )
396+ } )
397+
398+ it ( 'is a no-op when the pair is already even' , ( ) => {
399+ const tree = split (
400+ 'row' ,
401+ [ group ( 'g0' , [ 'a' ] ) , group ( 'g1' , [ 'b' ] ) ] ,
402+ [ 0.5 , 0.5 ] ,
403+ )
404+ expect ( resetSplit ( tree , [ ] , 0 ) ) . toEqual ( tree )
405+ } )
406+
407+ it ( 'is a no-op for a bad path or gutter' , ( ) => {
408+ const tree = split ( 'row' , [ group ( 'g0' , [ 'a' ] ) , group ( 'g1' , [ 'b' ] ) ] )
409+ expect ( resetSplit ( tree , [ 9 ] , 0 ) ) . toEqual ( tree )
410+ expect ( resetSplit ( tree , [ ] , 5 ) ) . toEqual ( tree )
411+ expect ( resetSplit ( group ( 'g0' , [ 'a' ] ) , [ ] , 0 ) ) . toEqual ( group ( 'g0' , [ 'a' ] ) )
412+ expect ( resetSplit ( null , [ ] , 0 ) ) . toBeNull ( )
413+ } )
414+ } )
415+
357416describe ( 'resizeFromPointer' , ( ) => {
358417 it ( 'applies total mouse travel to the snapshot so later moves do not compound' , ( ) => {
359418 const tree = split (
0 commit comments