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 tp = @import("thespian");
|
||||||
|
|
||||||
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,
|
||||||
commands: Commands = undefined,
|
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);
|
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),
|
||||||
};
|
};
|
||||||
try self.commands.init(self);
|
try self.commands.init(self);
|
||||||
return .{
|
return EventHandler.to_owned(self);
|
||||||
.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,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
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 {
|
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);
|
||||||
|
@ -300,6 +290,8 @@ fn cmd_async(self: *Self, name_: []const u8) tp.result {
|
||||||
return tp.self_pid().send(.{ "cmd", name_ });
|
return tp.self_pid().send(.{ "cmd", name_ });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const hints = keybind.KeybindHints.initComptime(.{});
|
||||||
|
|
||||||
const Commands = command.Collection(cmds_);
|
const Commands = command.Collection(cmds_);
|
||||||
const cmds_ = struct {
|
const cmds_ = struct {
|
||||||
pub const Target = Self;
|
pub const Target = Self;
|
|
@ -1,42 +1,31 @@
|
||||||
|
const std = @import("std");
|
||||||
const tp = @import("thespian");
|
const tp = @import("thespian");
|
||||||
|
|
||||||
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,
|
||||||
count: usize = 0,
|
count: usize = 0,
|
||||||
commands: Commands = undefined,
|
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);
|
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),
|
||||||
};
|
};
|
||||||
try self.commands.init(self);
|
try self.commands.init(self);
|
||||||
return .{
|
return EventHandler.to_owned(self);
|
||||||
.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,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
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 {
|
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);
|
||||||
|
@ -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);
|
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_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,42 +1,31 @@
|
||||||
|
const std = @import("std");
|
||||||
const tp = @import("thespian");
|
const tp = @import("thespian");
|
||||||
|
|
||||||
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,
|
||||||
count: usize = 0,
|
count: usize = 0,
|
||||||
commands: Commands = undefined,
|
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);
|
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),
|
||||||
};
|
};
|
||||||
try self.commands.init(self);
|
try self.commands.init(self);
|
||||||
return .{
|
return EventHandler.to_owned(self);
|
||||||
.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,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
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 {
|
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);
|
||||||
|
@ -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);
|
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_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" },
|
|
@ -7,6 +7,11 @@ pub const mode = struct {
|
||||||
pub const insert = @import("input/vim/insert.zig");
|
pub const insert = @import("input/vim/insert.zig");
|
||||||
pub const visual = @import("input/vim/visual.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 overlay = struct {
|
||||||
pub const palette = @import("overlay/palette.zig");
|
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 {
|
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 .{
|
return .{
|
||||||
.input_handler = try mode.create(self.allocator, opts),
|
.input_handler = try mode.create(self.allocator, opts),
|
||||||
.name = name,
|
.name = name,
|
||||||
|
@ -681,11 +680,20 @@ const cmds = struct {
|
||||||
.cursor_shape = .underline,
|
.cursor_shape = .underline,
|
||||||
})
|
})
|
||||||
else if (std.mem.eql(u8, mode, "helix/normal"))
|
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"))
|
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"))
|
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"))
|
else if (std.mem.eql(u8, mode, "flow"))
|
||||||
try self.static_mode(keybind.mode.input.flow, "flow", .{})
|
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"))
|
||||||
|
|
Loading…
Add table
Reference in a new issue