refactor: re-intruduce move_to_char direction indicator

This commit is contained in:
CJ van den Berg 2025-04-08 10:39:02 +02:00
parent fb985a703a
commit a3a6830043
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -16,25 +16,34 @@ const Commands = command.Collection(cmds);
allocator: Allocator, allocator: Allocator,
key: [6]u8 = undefined, key: [6]u8 = undefined,
direction: Direction,
operation_command: []const u8, operation_command: []const u8,
operation: Operation, operation: Operation,
commands: Commands = undefined, commands: Commands = undefined,
const Direction = enum {
left,
right,
};
const Operation = enum { const Operation = enum {
move, move,
select, select,
}; };
pub fn create(allocator: Allocator, ctx: command.Context) !struct { tui.Mode, tui.MiniMode } { pub fn create(allocator: Allocator, ctx: command.Context) !struct { tui.Mode, tui.MiniMode } {
var egc: []const u8 = undefined; var operation_command: []const u8 = undefined;
_ = ctx.args.match(.{tp.extract(&operation_command)}) catch return error.InvalidMoveToCharArgument;
const direction: Direction = if (std.mem.indexOf(u8, operation_command, "_left")) |_| .left else .right;
const operation: Operation = if (tui.get_active_editor()) |editor| if (editor.get_primary().selection) |_| .select else .move else .move;
const select = if (tui.get_active_editor()) |editor| if (editor.get_primary().selection) |_| true else false else false;
_ = ctx.args.match(.{tp.extract(&egc)}) catch return error.InvalidMoveToCharArgument;
const self: *Self = try allocator.create(Self); const self: *Self = try allocator.create(Self);
self.* = .{ self.* = .{
.allocator = allocator, .allocator = allocator,
.operation_command = try allocator.dupe(u8, egc), .direction = direction,
.operation = if (select) .select else .move, .operation_command = try allocator.dupe(u8, operation_command),
.operation = operation,
}; };
try self.commands.init(self); try self.commands.init(self);
var mode = try keybind.mode("mini/move_to_char", allocator, .{ var mode = try keybind.mode("mini/move_to_char", allocator, .{
@ -52,8 +61,14 @@ pub fn deinit(self: *Self) void {
fn name(self: *Self) []const u8 { fn name(self: *Self) []const u8 {
return switch (self.operation) { return switch (self.operation) {
.move => "move", .move => switch (self.direction) {
.select => "select", .left => "↶ move",
.right => "↷ move",
},
.select => switch (self.direction) {
.left => "󰒅 ↶ select",
.right => "󰒅 ↷ select",
},
}; };
} }