feat: add grow and shrink panel commands and keybindings

This commit is contained in:
CJ van den Berg 2026-04-08 16:29:38 +02:00
parent 6ea26a800a
commit 03b914ec6b
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 61 additions and 5 deletions

View file

@ -26,6 +26,10 @@
["ctrl+`", "open_terminal"],
["ctrl+j", "toggle_panel"],
["ctrl+shift+j", "toggle_maximize_panel"],
["ctrl+alt+home", "grow_panel"],
["ctrl+shift+alt+home", "grow_panel", 3],
["ctrl+alt+end", "shrink_panel"],
["ctrl+shift+alt+end", "shrink_panel", 3],
["ctrl+q", "quit"],
["ctrl+w", "close_split"],
["ctrl+o", "open_file"],
@ -354,6 +358,10 @@
["alt+!", "add_task"],
["ctrl+j", "toggle_panel"],
["ctrl+shift+j", "toggle_maximize_panel"],
["ctrl+alt+home", "grow_panel"],
["ctrl+shift+alt+home", "grow_panel", 3],
["ctrl+alt+end", "shrink_panel"],
["ctrl+shift+alt+end", "shrink_panel", 3],
["ctrl+q", "quit"],
["ctrl+w", "close_file"],
["ctrl+shift+f", "find_in_files"],
@ -523,6 +531,10 @@
["ctrl+alt+?", "scroll_keybind_hints"],
["alt+f9", "panel_next_widget_style"],
["ctrl+shift+j", "toggle_maximize_panel"],
["ctrl+alt+home", "grow_panel"],
["ctrl+shift+alt+home", "grow_panel", 3],
["ctrl+alt+end", "shrink_panel"],
["ctrl+shift+alt+end", "shrink_panel", 3],
["ctrl+q", "quit"],
["ctrl+v", "system_paste"],
["ctrl+u", "mini_mode_reset"],
@ -600,10 +612,16 @@
["ctrl+7", "focus_split", 6],
["ctrl+8", "focus_split", 7],
["ctrl+`", "unfocus_terminal"],
["ctrl+j", "toggle_panel"],
["ctrl+shift+page_down", "terminal_scroll_down"],
["ctrl+shift+page_up", "terminal_scroll_up"],
["ctrl+alt+page_down", "terminal_scroll_down"],
["ctrl+alt+page_up", "terminal_scroll_up"],
["ctrl+j", "toggle_panel"],
["ctrl+shift+j", "toggle_maximize_panel"],
["ctrl+alt+home", "grow_panel"],
["ctrl+shift+alt+home", "grow_panel", 3],
["ctrl+alt+end", "shrink_panel"],
["ctrl+shift+alt+end", "shrink_panel", 3],
["ctrl+shift+p", "open_command_palette"],
["alt+shift+p", "open_command_palette"],
["alt+x", "open_command_palette"],

View file

@ -280,20 +280,39 @@ fn handle_bottom_bar_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result
}
fn bottom_bar_primary_drag(self: *Self, y: usize) tp.result {
const h = @max(1, self.plane.dim_y() -| y);
return self.set_panel_height_abs(h);
}
fn set_panel_height_abs(self: *Self, y: usize) tp.result {
const panels = self.panels orelse blk: {
cmds.toggle_panel(self, .{}) catch return;
break :blk self.panels.?;
};
const h = self.plane.dim_y();
self.panel_height = @max(1, h - @min(h, y + 1));
const max_h = self.box().h -| 1;
std.log.debug("set_panel_height: {?d} {d}", .{ self.panel_height, y });
self.panel_height = @max(1, @min(max_h, y));
self.panel_maximized = false;
panels.layout_ = .{ .static = self.panel_height.? };
if (self.panel_height == 1) {
const panel_height = self.panel_height orelse return;
if (panel_height == 1) {
self.panel_height = null;
command.executeName("toggle_panel", .{}) catch {};
} else if (panel_height >= max_h) {
self.panel_maximized = true;
panels.layout_ = .{ .static = max_h };
self.panel_height = null;
}
}
fn set_panel_height_rel(self: *Self, y: isize) tp.result {
if (self.panels == null and y < 0) return;
if (self.panel_maximized and y > 0) return;
const panel_h: isize = @intCast(self.get_panel_height());
const h = @max(1, panel_h +| y);
return self.set_panel_height_abs(h);
}
pub fn get_panel_height(self: *Self) usize {
return self.panel_height orelse self.box().h / 5;
}
@ -942,7 +961,11 @@ const cmds = struct {
pub const toggle_panel_meta: Meta = .{ .description = "Toggle panel" };
pub fn toggle_maximize_panel(self: *Self, _: Ctx) Result {
const panels = self.panels orelse return;
const panels = self.panels orelse blk: {
cmds.toggle_panel(self, .{}) catch return;
self.panel_maximized = false;
break :blk self.panels.?;
};
const max_h = self.box().h -| 1;
if (self.panel_maximized) {
// Restore previous height
@ -957,6 +980,21 @@ const cmds = struct {
}
pub const toggle_maximize_panel_meta: Meta = .{ .description = "Toggle maximize panel" };
pub fn grow_panel(self: *Self, ctx: Ctx) Result {
var n: usize = 1;
_ = try ctx.args.match(.{tp.extract(&n)});
return self.set_panel_height_rel(@intCast(n));
}
pub const grow_panel_meta: Meta = .{ .description = "Make the panel larger" };
pub fn shrink_panel(self: *Self, ctx: Ctx) Result {
var n: usize = 1;
_ = try ctx.args.match(.{tp.extract(&n)});
const neg_n = 0 - @as(isize, @intCast(n));
return self.set_panel_height_rel(neg_n);
}
pub const shrink_panel_meta: Meta = .{ .description = "Make the panel smaller" };
pub fn toggle_logview(self: *Self, _: Ctx) Result {
try self.toggle_panel_view(logview, .toggle);
}