refactor: move helix mode keybindings to keybind module
This commit is contained in:
parent
d75e3dd9e3
commit
ced130b4f4
5 changed files with 48 additions and 65 deletions
|
@ -1,40 +1,30 @@
|
|||
const std = @import("std");
|
||||
const tp = @import("thespian");
|
||||
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
const tui = @import("../../../tui.zig");
|
||||
|
||||
const Allocator = @import("std").mem.Allocator;
|
||||
const ArrayList = @import("std").ArrayList;
|
||||
const eql = @import("std").mem.eql;
|
||||
const keybind = @import("../../keybind.zig");
|
||||
|
||||
const Self = @This();
|
||||
const input_buffer_size = 1024;
|
||||
|
||||
allocator: Allocator,
|
||||
input: ArrayList(u8),
|
||||
allocator: std.mem.Allocator,
|
||||
input: std.ArrayList(u8),
|
||||
last_cmd: []const u8 = "",
|
||||
leader: ?struct { keypress: u32, modifiers: u32 } = null,
|
||||
commands: Commands = undefined,
|
||||
|
||||
pub fn create(allocator: Allocator) !tui.Mode {
|
||||
pub fn create(allocator: std.mem.Allocator, _: anytype) !EventHandler {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
|
||||
.input = try std.ArrayList(u8).initCapacity(allocator, input_buffer_size),
|
||||
};
|
||||
try self.commands.init(self);
|
||||
return .{
|
||||
.input_handler = EventHandler.to_owned(self),
|
||||
.name = "INS",
|
||||
.line_numbers = if (tui.current().config.vim_insert_gutter_line_numbers_relative) .relative else .absolute,
|
||||
.cursor_shape = .beam,
|
||||
};
|
||||
return EventHandler.to_owned(self);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
|
@ -287,9 +277,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 {
|
||||
return if (eql(u8, self.last_cmd, name2))
|
||||
return if (std.mem.eql(u8, self.last_cmd, name2))
|
||||
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)
|
||||
else
|
||||
self.cmd(name1, ctx);
|
||||
|
@ -300,6 +290,8 @@ fn cmd_async(self: *Self, name_: []const u8) tp.result {
|
|||
return tp.self_pid().send(.{ "cmd", name_ });
|
||||
}
|
||||
|
||||
pub const hints = keybind.KeybindHints.initComptime(.{});
|
||||
|
||||
const Commands = command.Collection(cmds_);
|
||||
const cmds_ = struct {
|
||||
pub const Target = Self;
|
|
@ -1,42 +1,31 @@
|
|||
const std = @import("std");
|
||||
const tp = @import("thespian");
|
||||
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
const tui = @import("../../../tui.zig");
|
||||
|
||||
const Allocator = @import("std").mem.Allocator;
|
||||
const ArrayList = @import("std").ArrayList;
|
||||
const eql = @import("std").mem.eql;
|
||||
const keybind = @import("../../keybind.zig");
|
||||
|
||||
const Self = @This();
|
||||
const input_buffer_size = 1024;
|
||||
|
||||
allocator: Allocator,
|
||||
input: ArrayList(u8),
|
||||
allocator: std.mem.Allocator,
|
||||
input: std.ArrayList(u8),
|
||||
last_cmd: []const u8 = "",
|
||||
leader: ?struct { keypress: u32, modifiers: u32 } = null,
|
||||
count: usize = 0,
|
||||
commands: Commands = undefined,
|
||||
|
||||
pub fn create(allocator: Allocator) !tui.Mode {
|
||||
pub fn create(allocator: std.mem.Allocator, _: anytype) !EventHandler {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
|
||||
.input = try std.ArrayList(u8).initCapacity(allocator, input_buffer_size),
|
||||
};
|
||||
try self.commands.init(self);
|
||||
return .{
|
||||
.input_handler = EventHandler.to_owned(self),
|
||||
.name = "NOR",
|
||||
.line_numbers = if (tui.current().config.vim_normal_gutter_line_numbers_relative) .relative else .absolute,
|
||||
.keybind_hints = &hints,
|
||||
.cursor_shape = .block,
|
||||
};
|
||||
return EventHandler.to_owned(self);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
|
@ -504,9 +493,9 @@ fn cmd_count(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 {
|
||||
return if (eql(u8, self.last_cmd, name2))
|
||||
return if (std.mem.eql(u8, self.last_cmd, name2))
|
||||
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)
|
||||
else
|
||||
self.cmd(name1, ctx);
|
||||
|
@ -536,7 +525,7 @@ fn seq_count(self: *Self, cmds: anytype, ctx: command.Context) tp.result {
|
|||
try self.cmd(@field(cmds, field_info.name), ctx);
|
||||
}
|
||||
|
||||
const hints = tui.KeybindHints.initComptime(.{
|
||||
pub const hints = keybind.KeybindHints.initComptime(.{
|
||||
.{ "add_cursor_all_matches", "C-S-l" },
|
||||
.{ "add_cursor_down", "S-A-down" },
|
||||
.{ "add_cursor_next_match", "C-d" },
|
|
@ -1,42 +1,31 @@
|
|||
const std = @import("std");
|
||||
const tp = @import("thespian");
|
||||
|
||||
const key = @import("renderer").input.key;
|
||||
const mod = @import("renderer").input.modifier;
|
||||
const event_type = @import("renderer").input.event_type;
|
||||
const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8;
|
||||
const command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
const tui = @import("../../../tui.zig");
|
||||
|
||||
const Allocator = @import("std").mem.Allocator;
|
||||
const ArrayList = @import("std").ArrayList;
|
||||
const eql = @import("std").mem.eql;
|
||||
const keybind = @import("../../keybind.zig");
|
||||
|
||||
const Self = @This();
|
||||
const input_buffer_size = 1024;
|
||||
|
||||
allocator: Allocator,
|
||||
input: ArrayList(u8),
|
||||
allocator: std.mem.Allocator,
|
||||
input: std.ArrayList(u8),
|
||||
last_cmd: []const u8 = "",
|
||||
leader: ?struct { keypress: u32, modifiers: u32 } = null,
|
||||
count: usize = 0,
|
||||
commands: Commands = undefined,
|
||||
|
||||
pub fn create(allocator: Allocator) !tui.Mode {
|
||||
pub fn create(allocator: std.mem.Allocator, _: anytype) !EventHandler {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.input = try ArrayList(u8).initCapacity(allocator, input_buffer_size),
|
||||
.input = try std.ArrayList(u8).initCapacity(allocator, input_buffer_size),
|
||||
};
|
||||
try self.commands.init(self);
|
||||
return .{
|
||||
.input_handler = EventHandler.to_owned(self),
|
||||
.name = "SEL",
|
||||
.line_numbers = if (tui.current().config.vim_visual_gutter_line_numbers_relative) .relative else .absolute,
|
||||
.keybind_hints = &hints,
|
||||
.cursor_shape = .block,
|
||||
};
|
||||
return EventHandler.to_owned(self);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
|
@ -504,9 +493,9 @@ fn cmd_count(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 {
|
||||
return if (eql(u8, self.last_cmd, name2))
|
||||
return if (std.mem.eql(u8, self.last_cmd, name2))
|
||||
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)
|
||||
else
|
||||
self.cmd(name1, ctx);
|
||||
|
@ -536,7 +525,7 @@ fn seq_count(self: *Self, cmds: anytype, ctx: command.Context) tp.result {
|
|||
try self.cmd(@field(cmds, field_info.name), ctx);
|
||||
}
|
||||
|
||||
const hints = tui.KeybindHints.initComptime(.{
|
||||
pub const hints = keybind.KeybindHints.initComptime(.{
|
||||
.{ "add_cursor_all_matches", "C-S-l" },
|
||||
.{ "add_cursor_down", "S-A-down" },
|
||||
.{ "add_cursor_next_match", "C-d" },
|
|
@ -7,6 +7,11 @@ pub const mode = struct {
|
|||
pub const insert = @import("input/vim/insert.zig");
|
||||
pub const visual = @import("input/vim/visual.zig");
|
||||
};
|
||||
pub const helix = struct {
|
||||
pub const normal = @import("input/helix/normal.zig");
|
||||
pub const insert = @import("input/helix/insert.zig");
|
||||
pub const visual = @import("input/helix/select.zig");
|
||||
};
|
||||
};
|
||||
pub const overlay = struct {
|
||||
pub const palette = @import("overlay/palette.zig");
|
||||
|
|
|
@ -562,7 +562,6 @@ fn enter_overlay_mode(self: *Self, mode: type) command.Result {
|
|||
}
|
||||
|
||||
fn static_mode(self: *Self, mode: anytype, name: []const u8, opts: anytype) !Mode {
|
||||
// .line_numbers_relative = if (self.config.vim_normal_gutter_line_numbers_relative) .relative else .absolute,
|
||||
return .{
|
||||
.input_handler = try mode.create(self.allocator, opts),
|
||||
.name = name,
|
||||
|
@ -681,11 +680,20 @@ const cmds = struct {
|
|||
.cursor_shape = .underline,
|
||||
})
|
||||
else if (std.mem.eql(u8, mode, "helix/normal"))
|
||||
try @import("mode/input/helix/normal.zig").create(self.allocator)
|
||||
try self.static_mode(keybind.mode.input.helix.normal, "NOR", .{
|
||||
.line_numbers_relative = self.config.vim_normal_gutter_line_numbers_relative,
|
||||
.cursor_shape = .block,
|
||||
})
|
||||
else if (std.mem.eql(u8, mode, "helix/insert"))
|
||||
try @import("mode/input/helix/insert.zig").create(self.allocator)
|
||||
try self.static_mode(keybind.mode.input.helix.insert, "INS", .{
|
||||
.line_numbers_relative = self.config.vim_insert_gutter_line_numbers_relative,
|
||||
.cursor_shape = .beam,
|
||||
})
|
||||
else if (std.mem.eql(u8, mode, "helix/select"))
|
||||
try @import("mode/input/helix/select.zig").create(self.allocator)
|
||||
try self.static_mode(keybind.mode.input.helix.visual, "SEL", .{
|
||||
.line_numbers_relative = self.config.vim_visual_gutter_line_numbers_relative,
|
||||
.cursor_shape = .block,
|
||||
})
|
||||
else if (std.mem.eql(u8, mode, "flow"))
|
||||
try self.static_mode(keybind.mode.input.flow, "flow", .{})
|
||||
else if (std.mem.eql(u8, mode, "home"))
|
||||
|
|
Loading…
Add table
Reference in a new issue