@@ -108,10 +108,8 @@ def one_dimensional_line_tree?
108108 end
109109
110110 def all_indentation_levels
111- lines
112- . map ( &:indentation_level )
113- . select ( &:positive? )
114- . uniq
111+ levels = lines . map ( &:indentation_level ) . uniq
112+ normalized_indentation_levels ( levels )
115113 end
116114
117115 def find_boxes_to_elide_within ( pane )
@@ -146,13 +144,10 @@ def normalized_box_groups_at_decreasing_indentation_levels_within(pane)
146144 def box_groups_at_decreasing_indentation_levels_within ( pane )
147145 boxes_within_pane = boxes . select { |box | box . fits_fully_within? ( pane ) }
148146
147+ levels = boxes_within_pane . map ( &:indentation_level ) . uniq
148+
149149 possible_indentation_levels =
150- boxes_within_pane
151- . map ( &:indentation_level )
152- . select ( &:positive? )
153- . uniq
154- . sort
155- . reverse
150+ normalized_indentation_levels ( levels ) . sort . reverse
156151
157152 possible_indentation_levels . map do |indentation_level |
158153 boxes_within_pane . select do |box |
@@ -174,6 +169,14 @@ def filter_out_boxes_fully_contained_in_others(boxes)
174169 end
175170 end
176171
172+ def normalized_indentation_levels ( levels )
173+ # For flat structures (strings), include level 0
174+ return levels if levels . all? ( &:zero? )
175+
176+ # For nested structures (arrays, hashes), exclude level 0 (brackets)
177+ levels . select ( &:positive? )
178+ end
179+
177180 def combine_congruent_boxes ( boxes )
178181 combine ( boxes , on : :indentation_level )
179182 end
0 commit comments