diff options
Diffstat (limited to 'src/layout.zig')
| -rw-r--r-- | src/layout.zig | 72 |
1 files changed, 66 insertions, 6 deletions
diff --git a/src/layout.zig b/src/layout.zig index 40bce75a..6345c91a 100644 --- a/src/layout.zig +++ b/src/layout.zig @@ -27,8 +27,19 @@ pub const MovePlacement = struct { above_h: u16, }; +pub const Dir = enum { left, right, up, down }; + /// 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 { +pub fn focusDir(p: *Pardes, from: usize, dir: Dir) bool { + const b = nearest(p, from, dir) 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; +} + +/// The pane next to `from` in `dir`, by the screen. +pub fn nearest(p: *const Pardes, from: usize, dir: Dir) ?usize { const a = p.rects[from]; var best: ?usize = null; var best_d: i32 = 0; @@ -55,11 +66,60 @@ pub fn focusDir(p: *Pardes, from: usize, dir: enum { left, right, up, down }) bo best_d = d; } } - 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; + return best; +} + +/// Window mode's labels, one a pane in reading order (columns left to +/// right, each top to bottom); h, j, k and l move instead. ponytail: a +/// pane past the 22nd has no label and is reached by moving. +pub const window_labels = "asdfgqwertyuiopzxcvbnm"; + +/// The letter window mode shows on pane `id`. +pub fn windowLabel(p: *const Pardes, id: usize) ?u8 { + var n: usize = 0; + for (0..p.ncol) |c| for (p.col_panes[c][0..p.col_n[c]]) |pane| { + if (n == window_labels.len) return null; + if (pane == id) return window_labels[n]; + n += 1; + }; + return null; +} + +/// Window mode (SPC w, Ctrl-w): h/j/k/l (or the arrows) move an outline +/// from pane to pane and nothing else gets the keys; Enter or Esc focuses +/// the outlined pane, `:` its tag, and a pane's label letter that one. Up past a +/// column's top pane goes on to its tag, as the Up word does. Any other +/// key changes nothing. +pub fn windowKey(p: *Pardes, key: pardes.Key) void { + const at = p.window_pick orelse return; + if (p.panes[at] == null) { + p.window_pick = null; + return; + } + if (key.ctrl or key.alt) return; + for (config.window_keys) |wk| if (pardes.hit(key, &.{ wk.letter, wk.arrow })) { + const dir: Dir = switch (wk.cmd) { + .Left => .left, + .Down => .down, + .Up => .up, + else => .right, + }; + if (nearest(p, at, dir)) |next| { + p.window_pick = next; + } else if (dir == .up) { + p.window_pick = null; + p.active = at; + pardes.exec.runBuiltin(p, .Up, at, "", null); + } + return; + }; + const chosen = if (key.cp == pardes.Key.enter or key.cp == pardes.Key.escape or key.cp == ':') at else for (0..p.panes.len) |id| { + if (p.panes[id] != null and key.cp < 128 and windowLabel(p, id) == @as(u8, @intCast(key.cp))) break id; + } else return; + p.window_pick = null; + p.active = chosen; + p.panes[chosen].?.body.normal.clear(); + if (key.cp == ':') tagline.enterTag(p, p.panes[chosen].?); } /// Column `c`'s serial, handed out the first time it is asked for. |
