refactor(terminal): add keyboard scrolling keybinds
This commit is contained in:
parent
4157638892
commit
4affdf5688
2 changed files with 28 additions and 0 deletions
|
|
@ -39,6 +39,8 @@
|
||||||
["ctrl+shift+f", "find_in_files"],
|
["ctrl+shift+f", "find_in_files"],
|
||||||
["ctrl+shift+l", "toggle_panel"],
|
["ctrl+shift+l", "toggle_panel"],
|
||||||
["alt+shift+p", "open_command_palette"],
|
["alt+shift+p", "open_command_palette"],
|
||||||
|
["ctrl+shift+page_up", "terminal_scroll_up"],
|
||||||
|
["ctrl+shift+page_down", "terminal_scroll_down"],
|
||||||
["alt+n", "goto_next_file_or_diagnostic"],
|
["alt+n", "goto_next_file_or_diagnostic"],
|
||||||
["alt+p", "goto_prev_file_or_diagnostic"],
|
["alt+p", "goto_prev_file_or_diagnostic"],
|
||||||
["alt+l", "toggle_panel"],
|
["alt+l", "toggle_panel"],
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ focused: bool = false,
|
||||||
input_mode: Mode,
|
input_mode: Mode,
|
||||||
hover: bool = false,
|
hover: bool = false,
|
||||||
vt: *Vt,
|
vt: *Vt,
|
||||||
|
commands: Commands = undefined,
|
||||||
|
|
||||||
pub fn create(allocator: Allocator, parent: Plane) !Widget {
|
pub fn create(allocator: Allocator, parent: Plane) !Widget {
|
||||||
return create_with_args(allocator, parent, .{});
|
return create_with_args(allocator, parent, .{});
|
||||||
|
|
@ -88,6 +89,7 @@ pub fn create_with_args(allocator: Allocator, parent: Plane, ctx: command.Contex
|
||||||
.vt = &global_vt.?,
|
.vt = &global_vt.?,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try self.commands.init(self);
|
||||||
try tui.message_filters().add(MessageFilter.bind(self, receive_filter));
|
try tui.message_filters().add(MessageFilter.bind(self, receive_filter));
|
||||||
|
|
||||||
container.ctx = self;
|
container.ctx = self;
|
||||||
|
|
@ -179,6 +181,7 @@ pub fn deinit(self: *Self, allocator: Allocator) void {
|
||||||
// p.deinit(self.allocator);
|
// p.deinit(self.allocator);
|
||||||
// state = null;
|
// state = null;
|
||||||
// }
|
// }
|
||||||
|
self.commands.unregister();
|
||||||
self.plane.deinit();
|
self.plane.deinit();
|
||||||
allocator.destroy(self);
|
allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
@ -240,6 +243,29 @@ fn receive_filter(_: *Self, _: tp.pid_ref, m: tp.message) MessageFilter.Error!bo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Commands = command.Collection(cmds);
|
||||||
|
|
||||||
|
const cmds = struct {
|
||||||
|
pub const Target = Self;
|
||||||
|
const Ctx = command.Context;
|
||||||
|
const Meta = command.Metadata;
|
||||||
|
const Result = command.Result;
|
||||||
|
|
||||||
|
pub fn terminal_scroll_up(self: *Self, _: Ctx) Result {
|
||||||
|
const half_page = @max(1, self.vt.vt.front_screen.height / 2);
|
||||||
|
if (self.vt.vt.scroll(@intCast(half_page)))
|
||||||
|
tui.need_render(@src());
|
||||||
|
}
|
||||||
|
pub const terminal_scroll_up_meta: Meta = .{ .description = "Terminal: Scroll up" };
|
||||||
|
|
||||||
|
pub fn terminal_scroll_down(self: *Self, _: Ctx) Result {
|
||||||
|
const half_page = @max(1, self.vt.vt.front_screen.height / 2);
|
||||||
|
if (self.vt.vt.scroll(-@as(i32, @intCast(half_page))))
|
||||||
|
tui.need_render(@src());
|
||||||
|
}
|
||||||
|
pub const terminal_scroll_down_meta: Meta = .{ .description = "Terminal: Scroll down" };
|
||||||
|
};
|
||||||
|
|
||||||
const Vt = struct {
|
const Vt = struct {
|
||||||
vt: Terminal,
|
vt: Terminal,
|
||||||
env: std.process.EnvMap,
|
env: std.process.EnvMap,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue