refactor: simplify getting the active editor and selection

This commit is contained in:
CJ van den Berg 2024-12-11 20:54:53 +01:00
parent 4b3904d5f2
commit 038ed4da2b
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
10 changed files with 138 additions and 143 deletions

View file

@ -8,7 +8,6 @@ const command = @import("command");
const EventHandler = @import("EventHandler");
const tui = @import("../../tui.zig");
const mainview = @import("../../mainview.zig");
const Allocator = @import("std").mem.Allocator;
const fmt = @import("std").fmt;
@ -26,19 +25,17 @@ commands: Commands = undefined,
pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.MiniMode } {
const self: *Self = try allocator.create(Self);
if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| {
self.* = .{
.allocator = allocator,
.start = editor.get_primary().cursor.row + 1,
};
try self.commands.init(self);
var mode = try keybind.mode("mini/goto", allocator, .{
.insert_command = "mini_mode_insert_bytes",
});
mode.event_handler = EventHandler.to_owned(self);
return .{ mode, .{ .name = name } };
const editor = tui.get_active_editor() orelse return error.NotFound;
self.* = .{
.allocator = allocator,
.start = editor.get_primary().cursor.row + 1,
};
return error.NotFound;
try self.commands.init(self);
var mode = try keybind.mode("mini/goto", allocator, .{
.insert_command = "mini_mode_insert_bytes",
});
mode.event_handler = EventHandler.to_owned(self);
return .{ mode, .{ .name = name } };
}
pub fn deinit(self: *Self) void {