diff options
Diffstat (limited to 'src/layout.zig')
| -rw-r--r-- | src/layout.zig | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/layout.zig b/src/layout.zig index 3637f30e..116a64b8 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -995,7 +995,7 @@ pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool { if (needs_rebase) old_weight *= 2; if (id == source_id) { if (p.col_n[source_col] <= 1) return false; - absorbVWeight(p, id); + absorbVWeight(p, id, null); removePane(p, id); } else if (findPane(p, id) != null) return false; @@ -1033,13 +1033,16 @@ pub fn snapColWeights(p: *Pardes, c: usize) void { } } -pub fn absorbVWeight(p: *Pardes, id: usize) void { +/// Hand a closing pane's rows to `to`. With none named they go up: past any +/// results listing to the nearest pane above that is not one, or to the +/// pane below when the closing one is first in its column. +pub fn absorbVWeight(p: *Pardes, id: usize, to: ?usize) void { const f = findPane(p, id) orelse return; if (p.col_n[f.col] <= 1) return; snapColWeights(p, f.col); - var sib = if (f.idx > 0) p.col_panes[f.col][f.idx - 1] else p.col_panes[f.col][f.idx + 1]; + var sib = to orelse if (f.idx > 0) p.col_panes[f.col][f.idx - 1] else p.col_panes[f.col][f.idx + 1]; var k = f.idx; - while (k > 0) : (k -= 1) { + while (to == null and k > 0) : (k -= 1) { sib = p.col_panes[f.col][k - 1]; if (p.panes[sib]) |pp| if (if (pp.file) |ff| panes.Output.fileTraits(ff.output).doc else true) break; } @@ -1119,7 +1122,7 @@ pub fn toggleCollapse(p: *Pardes, id: usize) void { // Convert only visible panes to row weights. The toggle then changes one // pair, rather than letting the column redistribute the released space. snapColWeights(p, at.col); - const neighbor = collapseNeighbor(p, at.col, at.idx); + const neighbor = expandedNeighbor(p, at.col, at.idx, .above) orelse expandedNeighbor(p, at.col, at.idx, .below); if (was_collapsed) { if (neighbor) |other| { const wanted: u16 = @intFromFloat(@min(@as(f32, @floatFromInt(std.math.maxInt(u16))), @max(1, @round(remembered_height)))); @@ -1139,15 +1142,17 @@ pub fn toggleCollapse(p: *Pardes, id: usize) void { compute(p); } -fn collapseNeighbor(p: *Pardes, col: usize, index: usize) ?usize { - var above = index; - while (above > 0) { - above -= 1; - const id = p.col_panes[col][above]; +/// The nearest pane on one side of `index` in its column that is not folded +/// to its tag: the one Collapse lends rows to and Del k / Del j gives them +/// to. A folded pane only keeps its weight for later, so rows handed to it +/// would spread over the whole column instead. +pub fn expandedNeighbor(p: *const Pardes, col: usize, index: usize, side: enum { above, below }) ?usize { + var k = index; + while (if (side == .above) k > 0 else k + 1 < p.col_n[col]) { + k = if (side == .above) k - 1 else k + 1; + const id = p.col_panes[col][k]; if (p.panes[id]) |pane| if (!pane.collapsed) return id; } - for (p.col_panes[col][index + 1 .. p.col_n[col]]) |id| - if (p.panes[id]) |pane| if (!pane.collapsed) return id; return null; } |
