feat: Helix & Vim mode: adding more commands (#218)

* Helix mode: select_left

* select_to_char_right implementation

* Vim select_to_char_left

* Helix select_to_char_left

* Helix & Vim: select_end

* select_to_char_left: Avoid panic with no selection

* select_left_helix: handling panic and shrinking code

* Correcting helix left and right select

* Helix mode: select_left

* select_to_char_right implementation

* Vim select_to_char_left

* Helix select_to_char_left

* Helix & Vim: select_end

* select_to_char_left: Avoid panic with no selection

* select_left_helix: handling panic and shrinking code

* Correcting helix left and right select

* Enable_selection on init_command

* move_to_char modification

* move_or_select

---------

Co-authored-by: CJ van den Berg <cj@vdbonline.com>
This commit is contained in:
Levi 2025-04-08 05:28:29 -03:00 committed by GitHub
parent 716f871d03
commit fb985a703a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 126 additions and 43 deletions

View file

@ -1,3 +1,4 @@
const std = @import("std");
const tp = @import("thespian");
const input = @import("input");
@ -15,28 +16,24 @@ const Commands = command.Collection(cmds);
allocator: Allocator,
key: [6]u8 = undefined,
direction: Direction,
operation_command: []const u8,
operation: Operation,
commands: Commands = undefined,
const Direction = enum {
left,
right,
};
const Operation = enum {
move,
select,
};
pub fn create(allocator: Allocator, ctx: command.Context) !struct { tui.Mode, tui.MiniMode } {
var direction: Direction = undefined;
var egc: []const u8 = undefined;
const select = if (tui.get_active_editor()) |editor| if (editor.get_primary().selection) |_| true else false else false;
_ = ctx.args.match(.{tp.extract(&direction)}) catch return error.InvalidMoveToCharArgument;
_ = ctx.args.match(.{tp.extract(&egc)}) catch return error.InvalidMoveToCharArgument;
const self: *Self = try allocator.create(Self);
self.* = .{
.allocator = allocator,
.direction = direction,
.operation_command = try allocator.dupe(u8, egc),
.operation = if (select) .select else .move,
};
try self.commands.init(self);
@ -49,19 +46,14 @@ pub fn create(allocator: Allocator, ctx: command.Context) !struct { tui.Mode, tu
pub fn deinit(self: *Self) void {
self.commands.deinit();
self.allocator.free(self.operation_command);
self.allocator.destroy(self);
}
fn name(self: *Self) []const u8 {
return switch (self.operation) {
.move => switch (self.direction) {
.left => "↶ move",
.right => "↷ move",
},
.select => switch (self.direction) {
.left => "󰒅 ↶ select",
.right => "󰒅 ↷ select",
},
.move => "move",
.select => "select",
};
}
@ -70,17 +62,7 @@ pub fn receive(_: *Self, _: tp.pid_ref, _: tp.message) error{Exit}!bool {
}
fn execute_operation(self: *Self, ctx: command.Context) command.Result {
const cmd = switch (self.direction) {
.left => switch (self.operation) {
.move => "move_to_char_left",
.select => "select_to_char_left",
},
.right => switch (self.operation) {
.move => "move_to_char_right",
.select => "select_to_char_right",
},
};
try command.executeName(cmd, ctx);
try command.executeName(self.operation_command, ctx);
try command.executeName("exit_mini_mode", .{});
}