diff options
Diffstat (limited to 'main.zig')
| -rw-r--r-- | main.zig | 52 |
1 files changed, 39 insertions, 13 deletions
@@ -714,6 +714,12 @@ fn layoutRemove(l: *Layout, id: usize) void { while (k + 1 < l.col_n[c]) : (k += 1) l.col_terms[c][k] = l.col_terms[c][k + 1]; l.col_n[c] -= 1; if (l.col_n[c] == 0) { + // The column just emptied: hand its width to a neighbor (the column to its + // left, or right if it was the first) so the OTHER columns keep their widths + // and only that neighbor grows to fill the gap. Horizontal mirror of + // absorbVWeight; without it, wsum drops and every remaining column reflows + // sideways — an extra movement on delete. + if (l.ncol > 1) l.col_weight[if (c > 0) c - 1 else c + 1] += l.col_weight[c]; var j = c; while (j + 1 < l.ncol) : (j += 1) { l.col_terms[j] = l.col_terms[j + 1]; @@ -2309,21 +2315,41 @@ fn actOnSelection( (openFileView(gpa, rp, pl.line, sw, sh) catch null); if (opened) |nt| { terms[free] = nt; - // files/images live in the LEFT column (acme convention). - // Stack at its top with a fair share of the column height, - // then drop a leftover unused shell. - const lc = 0; - const ln = layout.col_n[lc]; - if (ln > 0) { - var vsum: f32 = 0; - for (0..ln) |i| if (terms[layout.col_terms[lc][i]]) |p| { - vsum += p.vweight; + // If a doc pane (file/image) already exists, SPLIT it + // (acme-style, minimal reflow): drop the new pane directly + // below the source and shrink ONLY it — the rest of the + // column keeps its sizes. Same rule as the tty right-click + // split. Prefer the pane the look came from when it's a doc; + // else the first doc pane (docs live in the LEFT column). + var src_id: ?usize = null; + if (t.file != null or t.image != null) src_id = id; + if (src_id == null) for (terms.*, 0..) |sl, i| { + if (sl) |p| if ((p.file != null or p.image != null) and i != free) { + src_id = i; + break; }; - nt.vweight = vsum / @as(f32, @floatFromInt(ln)); + }; + if (src_id) |sid| { + const sf = layoutFindTerm(layout, sid).?; + layoutInsert(layout, sf.col, sf.idx + 1, free); + splitBelow(terms[sid].?, nt, rects[sid].h); + active.* = free; + } else { + // No doc pane yet: stack at the top of the LEFT column + // with a fair share, then drop a leftover unused shell. + const lc = 0; + const ln = layout.col_n[lc]; + if (ln > 0) { + var vsum: f32 = 0; + for (0..ln) |i| if (terms[layout.col_terms[lc][i]]) |p| { + vsum += p.vweight; + }; + nt.vweight = vsum / @as(f32, @floatFromInt(ln)); + } + layoutInsert(layout, lc, 0, free); + active.* = free; + evictLonePristineTty(layout, terms, io, gpa, lc, free, active); } - layoutInsert(layout, lc, 0, free); - active.* = free; - evictLonePristineTty(layout, terms, io, gpa, lc, free, active); } } } |
