diff options
Diffstat (limited to 'src/layout.zig')
| -rw-r--r-- | src/layout.zig | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/layout.zig b/src/layout.zig index 49da0207..54b89081 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -674,7 +674,8 @@ pub const MovePlacement = struct { above_h: u16, }; -pub fn focusDir(p: *Pardes, from: usize, dir: enum { left, right, up, down }) void { +/// Move the keyboard to the nearest pane in `dir`; false when there is none. +pub fn focusDir(p: *Pardes, from: usize, dir: enum { left, right, up, down }) bool { const a = p.rects[from]; var best: ?usize = null; var best_d: i32 = 0; @@ -701,11 +702,11 @@ pub fn focusDir(p: *Pardes, from: usize, dir: enum { left, right, up, down }) vo best_d = d; } } - if (best) |b| { - p.active = b; - // a count typed before the hop was meant for the pane you left - p.panes[b].?.body.normal.clear(); - } + const b = best orelse return false; + p.active = b; + // a count typed before the hop was meant for the pane you left + p.panes[b].?.body.normal.clear(); + return true; } pub fn columnBySerial(p: *const Pardes, serial: u32) ?usize { @@ -935,6 +936,7 @@ pub fn removePane(p: *Pardes, id: usize) void { if (p.col_n[c] == 0) { p.exitHeader(); if (p.ncol > 1) p.col_weight[if (c > 0) c - 1 else c + 1] +|= p.col_weight[c]; + p.col_tags[c].deinit(p.gpa); var j = c; while (j + 1 < p.ncol) : (j += 1) { p.col_panes[j] = p.col_panes[j + 1]; @@ -944,7 +946,7 @@ pub fn removePane(p: *Pardes, id: usize) void { p.col_serial[j] = p.col_serial[j + 1]; } p.ncol -= 1; - p.col_tags[p.ncol] = .{}; + p.col_tags[p.ncol] = .{ .what = .column }; p.col_serial[p.ncol] = 0; } } @@ -958,6 +960,7 @@ pub fn joinCol(p: *Pardes) void { p.col_weight[dst] +|= p.col_weight[c]; for (0..p.col_n[c]) |k| p.col_panes[dst][p.col_n[dst] + k] = p.col_panes[c][k]; p.col_n[dst] += p.col_n[c]; + p.col_tags[c].deinit(p.gpa); var j = c; while (j + 1 < p.ncol) : (j += 1) { p.col_panes[j] = p.col_panes[j + 1]; @@ -967,7 +970,7 @@ pub fn joinCol(p: *Pardes) void { p.col_serial[j] = p.col_serial[j + 1]; } p.ncol -= 1; - p.col_tags[p.ncol] = .{}; + p.col_tags[p.ncol] = .{ .what = .column }; p.col_serial[p.ncol] = 0; } @@ -1017,7 +1020,7 @@ pub fn splitColumn(p: *Pardes, source_id: usize, id: usize, before: bool) bool { p.col_serial[j] = p.col_serial[j - 1]; } p.col_weight[c] = new_weight; - p.col_tags[c] = .{}; + p.col_tags[c] = .{ .what = .column }; p.col_serial[c] = 0; p.col_panes[c][0] = id; p.col_n[c] = 1; @@ -2245,25 +2248,25 @@ test "column reorder moves only crossed state and preserves weights" { p.col_weight[c] = c * 13 + 7; p.col_serial[c] = @intCast(c + 10); p.col_panes[c][0] = c; - p.col_tags[c].saved_col = @intCast(c + 20); + p.col_tags[c].cur_col = @intCast(c + 20); } compute(p); const original_weights = p.col_weight; const outer_x = p.col_x[0]; const outer_w = p.col_w[0]; + p.header_focus = true; p.header_column = 1; - p.topbar_col = 23; p.header_scroll = 9; reorderColumn(p, 1, 3); try std.testing.expectEqual(original_weights[1], p.col_weight[3]); try std.testing.expectEqual(original_weights[2], p.col_weight[1]); try std.testing.expectEqual(@as(u32, 11), p.col_serial[3]); try std.testing.expectEqual(@as(?usize, 3), p.header_column); - try std.testing.expectEqual(@as(?u16, 23), p.topbar_col); + try std.testing.expectEqual(@as(i32, 21), p.focusedHeader().?.cur_col); try std.testing.expectEqual(@as(usize, 9), p.header_scroll); try std.testing.expectEqual(outer_x, p.col_x[0]); try std.testing.expectEqual(outer_w, p.col_w[0]); reorderColumn(p, 3, 1); try std.testing.expectEqualSlices(u64, original_weights[0..4], p.col_weight[0..4]); - try std.testing.expectEqual(@as(?u16, 21), p.col_tags[1].saved_col); + try std.testing.expectEqual(@as(i32, 21), p.col_tags[1].cur_col); } |
