diff --git a/CHANGELOG.md b/CHANGELOG.md index 2088fe1b..0fe11aec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Fix integration snippet indentation. [#299](https://github.com/splitwise/super_diff/pull/299) by [@gschlager](https://github.com/gschlager) - Pin all actions to full commit SHA. [#305](https://github.com/splitwise/super_diff/pull/305) - Do not attempt to sub-diff multiline strings. [#304](https://github.com/splitwise/super_diff/pull/304) +- Tweak TieredLinesElider. [#307](https://github.com/splitwise/super_diff/pull/307) ## 0.18.0 - 2025-12-05 diff --git a/lib/super_diff/core/tiered_lines_elider.rb b/lib/super_diff/core/tiered_lines_elider.rb index 1624b3fa..4d4e06a9 100644 --- a/lib/super_diff/core/tiered_lines_elider.rb +++ b/lib/super_diff/core/tiered_lines_elider.rb @@ -99,8 +99,10 @@ def one_dimensional_line_tree? end def all_indentation_levels - levels = lines.map(&:indentation_level).uniq - normalized_indentation_levels(levels) + lines + .reject(&:complete_bookend?) + .map(&:indentation_level) + .uniq end def find_boxes_to_elide_within(pane) @@ -129,7 +131,7 @@ def find_boxes_to_elide_within(pane) def normalized_box_groups_at_decreasing_indentation_levels_within(pane) box_groups_at_decreasing_indentation_levels_within(pane).map( &method(:filter_out_boxes_fully_contained_in_others) - ).map(&method(:combine_congruent_boxes)) + ).map(&method(:combine_contiguous_boxes)) end def box_groups_at_decreasing_indentation_levels_within(pane) @@ -137,8 +139,7 @@ def box_groups_at_decreasing_indentation_levels_within(pane) levels = boxes_within_pane.map(&:indentation_level).uniq - possible_indentation_levels = - normalized_indentation_levels(levels).sort.reverse + possible_indentation_levels = levels.sort.reverse possible_indentation_levels.map do |indentation_level| boxes_within_pane.select do |box| @@ -167,15 +168,7 @@ def filter_out_boxes_fully_contained_in_others(boxes) end end - def normalized_indentation_levels(levels) - # For flat structures (strings), include level 0 - return levels if levels.all?(&:zero?) - - # For nested structures (arrays, hashes), exclude level 0 (brackets) - levels.select(&:positive?) - end - - def combine_congruent_boxes(boxes) + def combine_contiguous_boxes(boxes) combine(boxes, on: :indentation_level) end