refactor: move home keybindings to keybind module
This commit is contained in:
parent
2a9e532340
commit
07a412c2b2
3 changed files with 16 additions and 12 deletions
|
@ -1,14 +1,11 @@
|
|||
const std = @import("std");
|
||||
const tp = @import("thespian");
|
||||
const root = @import("root");
|
||||
|
||||
const key = @import("renderer").input.key;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
const tui = @import("../../tui.zig");
|
||||
const keybind = @import("../root.zig");
|
||||
|
||||
const Self = @This();
|
||||
|
||||
|
@ -16,16 +13,12 @@ allocator: std.mem.Allocator,
|
|||
f: usize = 0,
|
||||
leader: ?struct { keypress: u32, modifiers: u32 } = null,
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !tui.Mode {
|
||||
pub fn create(allocator: std.mem.Allocator) !EventHandler {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
};
|
||||
return .{
|
||||
.input_handler = EventHandler.to_owned(self),
|
||||
.name = root.application_name,
|
||||
.keybind_hints = &hints,
|
||||
};
|
||||
return EventHandler.to_owned(self);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
|
@ -155,7 +148,7 @@ fn sheeran(self: *Self) void {
|
|||
}
|
||||
}
|
||||
|
||||
const hints = tui.KeybindHints.initComptime(.{
|
||||
pub const hints = keybind.KeybindHints.initComptime(.{
|
||||
.{ "find_in_files", "C-S-f" },
|
||||
.{ "open_file", "o, C-o" },
|
||||
.{ "open_recent", "e, C-e" },
|
|
@ -1,4 +1,7 @@
|
|||
pub const mode = struct {
|
||||
pub const input = struct {
|
||||
pub const home = @import("input/home.zig");
|
||||
};
|
||||
pub const overlay = struct {
|
||||
pub const palette = @import("overlay/palette.zig");
|
||||
};
|
||||
|
|
|
@ -561,6 +561,14 @@ fn enter_overlay_mode(self: *Self, mode: type) command.Result {
|
|||
self.refresh_hover();
|
||||
}
|
||||
|
||||
fn static_mode(self: *Self, mode: anytype, name: []const u8) !Mode {
|
||||
return .{
|
||||
.input_handler = try mode.create(self.allocator),
|
||||
.name = name,
|
||||
.keybind_hints = &mode.hints,
|
||||
};
|
||||
}
|
||||
|
||||
const cmds = struct {
|
||||
pub const Target = Self;
|
||||
const Ctx = command.Context;
|
||||
|
@ -662,7 +670,7 @@ const cmds = struct {
|
|||
else if (std.mem.eql(u8, mode, "flow"))
|
||||
try @import("mode/input/flow.zig").create(self.allocator)
|
||||
else if (std.mem.eql(u8, mode, "home"))
|
||||
try @import("mode/input/home.zig").create(self.allocator)
|
||||
try self.static_mode(keybind.mode.input.home, "home")
|
||||
else ret: {
|
||||
self.logger.print("unknown mode {s}", .{mode});
|
||||
break :ret try @import("mode/input/flow.zig").create(self.allocator);
|
||||
|
|
Loading…
Add table
Reference in a new issue