refactor: move flow mode keybindings to keybind module
This commit is contained in:
parent
b2c81c50ed
commit
4be4fe76e9
3 changed files with 13 additions and 22 deletions
|
@ -1,38 +1,28 @@
|
||||||
|
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 mod = @import("renderer").input.modifier;
|
const mod = @import("renderer").input.modifier;
|
||||||
const event_type = @import("renderer").input.event_type;
|
const event_type = @import("renderer").input.event_type;
|
||||||
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
|
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
|
||||||
const command = @import("command");
|
const command = @import("command");
|
||||||
const EventHandler = @import("EventHandler");
|
const EventHandler = @import("EventHandler");
|
||||||
|
const keybind = @import("../keybind.zig");
|
||||||
const tui = @import("../../tui.zig");
|
|
||||||
|
|
||||||
const Allocator = @import("std").mem.Allocator;
|
|
||||||
const ArrayList = @import("std").ArrayList;
|
|
||||||
const eql = @import("std").mem.eql;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
const input_buffer_size = 1024;
|
const input_buffer_size = 1024;
|
||||||
|
|
||||||
allocator: Allocator,
|
allocator: std.mem.Allocator,
|
||||||
input: ArrayList(u8),
|
input: std.ArrayList(u8),
|
||||||
last_cmd: []const u8 = "",
|
last_cmd: []const u8 = "",
|
||||||
leader: ?struct { keypress: u32, modifiers: u32 } = null,
|
leader: ?struct { keypress: u32, modifiers: u32 } = null,
|
||||||
|
|
||||||
pub fn create(allocator: 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,
|
||||||
.input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
|
.input = try std.ArrayList(u8).initCapacity(allocator, input_buffer_size),
|
||||||
};
|
|
||||||
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 {
|
pub fn deinit(self: *Self) void {
|
||||||
|
@ -304,9 +294,9 @@ fn cmd(self: *Self, name_: []const u8, ctx: command.Context) tp.result {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cmd_cycle3(self: *Self, name1: []const u8, name2: []const u8, name3: []const u8, ctx: command.Context) tp.result {
|
fn cmd_cycle3(self: *Self, name1: []const u8, name2: []const u8, name3: []const u8, ctx: command.Context) tp.result {
|
||||||
return if (eql(u8, self.last_cmd, name2))
|
return if (std.mem.eql(u8, self.last_cmd, name2))
|
||||||
self.cmd(name3, ctx)
|
self.cmd(name3, ctx)
|
||||||
else if (eql(u8, self.last_cmd, name1))
|
else if (std.mem.eql(u8, self.last_cmd, name1))
|
||||||
self.cmd(name2, ctx)
|
self.cmd(name2, ctx)
|
||||||
else
|
else
|
||||||
self.cmd(name1, ctx);
|
self.cmd(name1, ctx);
|
||||||
|
@ -317,7 +307,7 @@ fn cmd_async(self: *Self, name_: []const u8) tp.result {
|
||||||
return tp.self_pid().send(.{ "cmd", name_ });
|
return tp.self_pid().send(.{ "cmd", name_ });
|
||||||
}
|
}
|
||||||
|
|
||||||
const hints = tui.KeybindHints.initComptime(.{
|
pub const hints = keybind.KeybindHints.initComptime(.{
|
||||||
.{ "add_cursor_all_matches", "C-S-l" },
|
.{ "add_cursor_all_matches", "C-S-l" },
|
||||||
.{ "add_cursor_down", "S-A-down" },
|
.{ "add_cursor_down", "S-A-down" },
|
||||||
.{ "add_cursor_next_match", "C-d" },
|
.{ "add_cursor_next_match", "C-d" },
|
|
@ -1,5 +1,6 @@
|
||||||
pub const mode = struct {
|
pub const mode = struct {
|
||||||
pub const input = struct {
|
pub const input = struct {
|
||||||
|
pub const flow = @import("input/flow.zig");
|
||||||
pub const home = @import("input/home.zig");
|
pub const home = @import("input/home.zig");
|
||||||
};
|
};
|
||||||
pub const overlay = struct {
|
pub const overlay = struct {
|
||||||
|
|
|
@ -668,12 +668,12 @@ const cmds = struct {
|
||||||
else if (std.mem.eql(u8, mode, "helix/select"))
|
else if (std.mem.eql(u8, mode, "helix/select"))
|
||||||
try @import("mode/input/helix/select.zig").create(self.allocator)
|
try @import("mode/input/helix/select.zig").create(self.allocator)
|
||||||
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 self.static_mode(keybind.mode.input.flow, "flow")
|
||||||
else if (std.mem.eql(u8, mode, "home"))
|
else if (std.mem.eql(u8, mode, "home"))
|
||||||
try self.static_mode(keybind.mode.input.home, "home")
|
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 self.static_mode(keybind.mode.input.flow, "flow");
|
||||||
};
|
};
|
||||||
// self.logger.print("input mode: {s}", .{(self.input_mode orelse return).description});
|
// self.logger.print("input mode: {s}", .{(self.input_mode orelse return).description});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue