@@ -99,10 +99,8 @@ def one_dimensional_line_tree?
9999 end
100100
101101 def all_indentation_levels
102- lines
103- . map ( &:indentation_level )
104- . select ( &:positive? )
105- . uniq
102+ levels = lines . map ( &:indentation_level ) . uniq
103+ normalized_indentation_levels ( levels )
106104 end
107105
108106 def find_boxes_to_elide_within ( pane )
@@ -137,13 +135,10 @@ def normalized_box_groups_at_decreasing_indentation_levels_within(pane)
137135 def box_groups_at_decreasing_indentation_levels_within ( pane )
138136 boxes_within_pane = boxes . select { |box | box . fits_fully_within? ( pane ) }
139137
138+ levels = boxes_within_pane . map ( &:indentation_level ) . uniq
139+
140140 possible_indentation_levels =
141- boxes_within_pane
142- . map ( &:indentation_level )
143- . select ( &:positive? )
144- . uniq
145- . sort
146- . reverse
141+ normalized_indentation_levels ( levels ) . sort . reverse
147142
148143 possible_indentation_levels . map do |indentation_level |
149144 boxes_within_pane . select do |box |
@@ -172,6 +167,14 @@ def filter_out_boxes_fully_contained_in_others(boxes)
172167 end
173168 end
174169
170+ def normalized_indentation_levels ( levels )
171+ # For flat structures (strings), include level 0
172+ return levels if levels . all? ( &:zero? )
173+
174+ # For nested structures (arrays, hashes), exclude level 0 (brackets)
175+ levels . select ( &:positive? )
176+ end
177+
175178 def combine_congruent_boxes ( boxes )
176179 combine ( boxes , on : :indentation_level )
177180 end
0 commit comments