refactor: move move_to_char mine mode keybinds
This commit is contained in:
parent
f67bfab5b7
commit
9724decc4a
4 changed files with 98 additions and 23 deletions
|
@ -11,9 +11,7 @@ const fmt = @import("std").fmt;
|
|||
const Mode = @import("root.zig").Mode;
|
||||
|
||||
pub fn create(_: Allocator) error{OutOfMemory}!Mode {
|
||||
return .{
|
||||
.handler = EventHandler.static(@This()),
|
||||
};
|
||||
return .{ .handler = EventHandler.static(@This()) };
|
||||
}
|
||||
|
||||
pub fn receive(_: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
|
|
56
src/keybind/static/move_to_char.zig
Normal file
56
src/keybind/static/move_to_char.zig
Normal file
|
@ -0,0 +1,56 @@
|
|||
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 command = @import("command");
|
||||
const EventHandler = @import("EventHandler");
|
||||
|
||||
const Allocator = @import("std").mem.Allocator;
|
||||
|
||||
const Mode = @import("root.zig").Mode;
|
||||
|
||||
pub fn create(_: Allocator) !Mode {
|
||||
return .{ .handler = EventHandler.static(@This()) };
|
||||
}
|
||||
|
||||
pub fn receive(_: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
var evtype: u32 = undefined;
|
||||
var keypress: u32 = undefined;
|
||||
var modifiers: u32 = undefined;
|
||||
var egc: u32 = undefined;
|
||||
if (try m.match(.{ "I", tp.extract(&evtype), tp.extract(&keypress), tp.extract(&egc), tp.string, tp.extract(&modifiers) }))
|
||||
try mapEvent(evtype, keypress, egc, modifiers);
|
||||
return false;
|
||||
}
|
||||
|
||||
fn mapEvent(evtype: u32, keypress: u32, egc: u32, modifiers: u32) tp.result {
|
||||
switch (evtype) {
|
||||
event_type.PRESS => try mapPress(keypress, egc, modifiers),
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
|
||||
fn mapPress(keypress: u32, egc: u32, modifiers: u32) tp.result {
|
||||
switch (keypress) {
|
||||
key.LSUPER, key.RSUPER => return,
|
||||
key.LSHIFT, key.RSHIFT => return,
|
||||
key.LCTRL, key.RCTRL => return,
|
||||
key.LALT, key.RALT => return,
|
||||
else => {},
|
||||
}
|
||||
return switch (modifiers) {
|
||||
mod.SHIFT => if (!key.synthesized_p(keypress))
|
||||
command.executeName("mini_mode_insert_code_point", command.fmt(.{egc}))
|
||||
else
|
||||
command.executeName("mini_mode_cancel", .{}),
|
||||
0 => switch (keypress) {
|
||||
key.ESC => command.executeName("mini_mode_cancel", .{}),
|
||||
key.ENTER => command.executeName("mini_mode_cancel", .{}),
|
||||
else => if (!key.synthesized_p(keypress))
|
||||
command.executeName("mini_mode_insert_code_point", command.fmt(.{egc}))
|
||||
else
|
||||
command.executeName("mini_mode_cancel", .{}),
|
||||
},
|
||||
else => command.executeName("mini_mode_cancel", .{}),
|
||||
};
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
pub const mode = struct {
|
||||
pub const mini = struct {
|
||||
pub const goto = @import("goto.zig");
|
||||
pub const move_to_char = @import("move_to_char.zig");
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue