Commit beda1d3
authored
Remove indentation level special-casing in TieredLinesElider (#307)
As
[promised](#300 (review)).
Two minor changes:
First, in `#all_indentation_levels`, we were excluding bookends by
inference: specifically, we assumed that if there were nonzero
indentation levels, the lines with indentation level zero must be
top-level bookends. We can just ask if `&:complete_bookend?` instead.
Second – and this one is more complicated – it turns out we don't need
to exclude level 0 from
`box_groups_at_decreasing_indentation_levels_within(pane)`. Why?
First, note that only clean panes are ever elided. Furthermore, we can
assume that there is at least one dirty pane; otherwise, we [don't try
to
elide](https://github.com/splitwise/super_diff/blob/a14d17283fb9827db003f848be79c2003fac5e95/lib/super_diff/core/tiered_lines_elider.rb#L14).
Now: for a _top-level_ structure (no nesting), such as a multi-line
string, we want to include level-0 boxes for elision. For _nested_
structures, we don't, because we don't want to elide the bookend
symbols/lines, such as `{`/`}` for a Hash `[`/`]` for an Array, etc.
However, a level-0 box for a _nested_ structure necessarily spans the
entire structure and therefore all lines; it starts with the open
bookend and ends with the close bookend. And since there is at least one
dirty pane, it's not possible for that level-0 box to fit within any
given pane. Thus, level-0 boxes for nested structured will be [filtered
out of
`boxes_within_pane`](https://github.com/splitwise/super_diff/blob/a14d17283fb9827db003f848be79c2003fac5e95/lib/super_diff/core/tiered_lines_elider.rb#L138).
So, for nested structures, `possible_indentation_levels` will still
exclude 0. For flat top-level structures, a top-level box would have
been created for each top-level line, so it should still _include_ zero.1 parent e767257 commit beda1d3
2 files changed
+8
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
| |||
129 | 131 | | |
130 | 132 | | |
131 | 133 | | |
132 | | - | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
137 | 139 | | |
138 | 140 | | |
139 | 141 | | |
140 | | - | |
141 | | - | |
| 142 | + | |
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
| |||
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 171 | + | |
179 | 172 | | |
180 | 173 | | |
181 | 174 | | |
| |||
0 commit comments