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 std = @import("std");
|
||||||
const tp = @import("thespian");
|
const tp = @import("thespian");
|
||||||
const root = @import("root");
|
|
||||||
|
|
||||||
const key = @import("renderer").input.key;
|
const key = @import("renderer").input.key;
|
||||||
const event_type = @import("renderer").input.event_type;
|
const event_type = @import("renderer").input.event_type;
|
||||||
const mod = @import("renderer").input.modifier;
|
const mod = @import("renderer").input.modifier;
|
||||||
const command = @import("command");
|
const command = @import("command");
|
||||||
const EventHandler = @import("EventHandler");
|
const EventHandler = @import("EventHandler");
|
||||||
|
const keybind = @import("../root.zig");
|
||||||
const tui = @import("../../tui.zig");
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
|
@ -16,16 +13,12 @@ allocator: std.mem.Allocator,
|
||||||
f: usize = 0,
|
f: usize = 0,
|
||||||
leader: ?struct { keypress: u32, modifiers: u32 } = null,
|
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);
|
const self: *Self = try allocator.create(Self);
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
};
|
};
|
||||||
return .{
|
return EventHandler.to_owned(self);
|
||||||
.input_handler = EventHandler.to_owned(self),
|
|
||||||
.name = root.application_name,
|
|
||||||
.keybind_hints = &hints,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
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" },
|
.{ "find_in_files", "C-S-f" },
|
||||||
.{ "open_file", "o, C-o" },
|
.{ "open_file", "o, C-o" },
|
||||||
.{ "open_recent", "e, C-e" },
|
.{ "open_recent", "e, C-e" },
|
|
@ -1,4 +1,7 @@
|
||||||
pub const mode = struct {
|
pub const mode = struct {
|
||||||
|
pub const input = struct {
|
||||||
|
pub const home = @import("input/home.zig");
|
||||||
|
};
|
||||||
pub const overlay = struct {
|
pub const overlay = struct {
|
||||||
pub const palette = @import("overlay/palette.zig");
|
pub const palette = @import("overlay/palette.zig");
|
||||||
};
|
};
|
||||||
|
|
|
@ -561,6 +561,14 @@ fn enter_overlay_mode(self: *Self, mode: type) command.Result {
|
||||||
self.refresh_hover();
|
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 {
|
const cmds = struct {
|
||||||
pub const Target = Self;
|
pub const Target = Self;
|
||||||
const Ctx = command.Context;
|
const Ctx = command.Context;
|
||||||
|
@ -662,7 +670,7 @@ const cmds = struct {
|
||||||
else if (std.mem.eql(u8, mode, "flow"))
|
else if (std.mem.eql(u8, mode, "flow"))
|
||||||
try @import("mode/input/flow.zig").create(self.allocator)
|
try @import("mode/input/flow.zig").create(self.allocator)
|
||||||
else if (std.mem.eql(u8, mode, "home"))
|
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: {
|
else ret: {
|
||||||
self.logger.print("unknown mode {s}", .{mode});
|
self.logger.print("unknown mode {s}", .{mode});
|
||||||
break :ret try @import("mode/input/flow.zig").create(self.allocator);
|
break :ret try @import("mode/input/flow.zig").create(self.allocator);
|
||||||
|
|
Loading…
Add table
Reference in a new issue