feat: add toggle_highlight_columns command (shift+f11)

This commit is contained in:
CJ van den Berg 2025-04-30 09:59:59 +02:00
parent ce2c370cfd
commit df70384b7b
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 12 additions and 1 deletions

View file

@ -157,6 +157,7 @@
["f9", "theme_prev"],
["f10", "theme_next"],
["f11", "toggle_panel"],
["shift+f11", "toggle_highlight_columns"],
["ctrl+f11", "toggle_inspector_view"],
["f12", "goto_definition"],
["f34", "toggle_whitespace_mode"],

View file

@ -24,6 +24,7 @@ allocator: Allocator,
rdr_: renderer,
config_: @import("config"),
highlight_columns_: []u16,
highlight_columns_configured: []u16,
frame_time: usize, // in microseconds
frame_clock: tp.metronome,
frame_clock_running: bool = false,
@ -130,12 +131,14 @@ fn init(allocator: Allocator) InitError!*Self {
idx += 1;
break :blk idx;
};
const highlight_columns__ = try allocator.alloc(u16, hl_cols);
var self = try allocator.create(Self);
self.* = .{
.allocator = allocator,
.config_ = conf,
.highlight_columns_ = try allocator.alloc(u16, hl_cols),
.highlight_columns_ = highlight_columns__,
.highlight_columns_configured = highlight_columns__,
.rdr_ = try renderer.init(allocator, self, tp.env.get().is("no-alternate"), dispatch_initialized),
.frame_time = frame_time,
.frame_clock = frame_clock,
@ -221,6 +224,7 @@ fn init_delayed(self: *Self) command.Result {
}
fn deinit(self: *Self) void {
self.allocator.free(self.highlight_columns_configured);
if (self.mouse_idle_timer) |*t| {
t.cancel() catch {};
t.deinit();
@ -788,6 +792,12 @@ const cmds = struct {
}
pub const toggle_whitespace_mode_meta: Meta = .{ .description = "Next whitespace mode" };
pub fn toggle_highlight_columns(self: *Self, _: Ctx) Result {
defer self.logger.print("highlight columns {s}", .{if (self.highlight_columns_.len > 0) "enabled" else "disabled"});
self.highlight_columns_ = if (self.highlight_columns_.len > 0) &.{} else self.highlight_columns_configured;
}
pub const toggle_highlight_columns_meta: Meta = .{ .description = "Toggle highlight columns" };
pub fn toggle_input_mode(self: *Self, _: Ctx) Result {
var it = std.mem.splitScalar(u8, self.config_.input_mode, '/');
self.config_.input_mode = it.first();