@@ -1991,4 +1991,52 @@ describe("CollapsibleTree.fromWithPreviousShape", () => {
19911991 expect ( tree . isCollapsed ( "one" ) ) . toBe ( false ) ;
19921992 expect ( tree . topLevelIds ) . toEqual ( [ "one" , "three" , "four" ] ) ;
19931993 } ) ;
1994+
1995+ it ( "reproduces GitHub issue #6188: inOrderIds with nested collapses" , ( ) => {
1996+ // Simplified reproduction case:
1997+ // Cell A (markdown): # Section 1 Header
1998+ // Cell B (markdown): ## Subsection 1.1 Header
1999+ // Cell C (python): print("This cell should be in Subsection 1.1")
2000+ // Cell D (python): print("This cell should also be in Subsection 1.1")
2001+ // Cell E (markdown): ## Subsection 1.2 Header
2002+ // Cell F (python): print("This cell should be in Subsection 1.2")
2003+
2004+ const originalOrder = [
2005+ "CellA" , // # Section 1 Header
2006+ "CellB" , // ## Subsection 1.1 Header
2007+ "CellC" , // print("This cell should be in Subsection 1.1")
2008+ "CellD" , // print("This cell should also be in Subsection 1.1")
2009+ "CellE" , // ## Subsection 1.2 Header
2010+ "CellF" , // print("This cell should be in Subsection 1.2")
2011+ ] ;
2012+
2013+ // Create notebook with one column
2014+ let notebook = MultiColumn . from ( [ originalOrder ] ) ;
2015+
2016+ // Before collapsing, order should be correct
2017+ expect ( notebook . inOrderIds ) . toEqual ( originalOrder ) ;
2018+
2019+ const columnId = notebook . getColumnIds ( ) [ 0 ] ;
2020+
2021+ // Follow the exact reproduction steps from the GitHub issue:
2022+ // 1. Collapse B (subsection 1.1) - includes C, D (stops before E)
2023+ notebook = notebook . transform ( columnId , ( tree ) =>
2024+ tree . collapse ( "CellB" , "CellD" ) ,
2025+ ) ;
2026+
2027+ // 2. Collapse E (subsection 1.2) - includes F (to end)
2028+ notebook = notebook . transform ( columnId , ( tree ) =>
2029+ tree . collapse ( "CellE" , undefined ) ,
2030+ ) ;
2031+
2032+ // 3. Collapse A (section 1) - includes all the rest (B, E and their children)
2033+ notebook = notebook . transform ( columnId , ( tree ) =>
2034+ tree . collapse ( "CellA" , undefined ) ,
2035+ ) ;
2036+
2037+ const finalOrder = notebook . inOrderIds ;
2038+
2039+ // inOrderIds now correctly preserves logical order even with nested collapses
2040+ expect ( finalOrder ) . toEqual ( originalOrder ) ;
2041+ } ) ;
19942042} ) ;
0 commit comments