fix: task_palette should use the correct mode hints for width calculations
This commit is contained in:
parent
54c68df967
commit
1600bf6406
2 changed files with 10 additions and 7 deletions
|
|
@ -27,6 +27,7 @@ pub fn Create(options: type) type {
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
modal: *ModalBackground.State(*Self),
|
modal: *ModalBackground.State(*Self),
|
||||||
menu: *Menu.State(*Self),
|
menu: *Menu.State(*Self),
|
||||||
|
mode: keybind.Mode,
|
||||||
inputbox: *InputBox.State(*Self),
|
inputbox: *InputBox.State(*Self),
|
||||||
logger: log.Logger,
|
logger: log.Logger,
|
||||||
longest: usize = 0,
|
longest: usize = 0,
|
||||||
|
|
@ -83,13 +84,20 @@ pub fn Create(options: type) type {
|
||||||
}))).dynamic_cast(InputBox.State(*Self)) orelse unreachable,
|
}))).dynamic_cast(InputBox.State(*Self)) orelse unreachable,
|
||||||
.view_rows = get_view_rows(tui.screen()),
|
.view_rows = get_view_rows(tui.screen()),
|
||||||
.entries = .empty,
|
.entries = .empty,
|
||||||
|
.mode = try keybind.mode("overlay/palette", allocator, .{
|
||||||
|
.insert_command = "overlay_insert_bytes",
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
try self.commands.init(self);
|
try self.commands.init(self);
|
||||||
|
self.mode.event_handler = EventHandler.to_owned(self);
|
||||||
|
self.mode.name = options.name;
|
||||||
if (self.menu.scrollbar) |scrollbar| scrollbar.style_factory = scrollbar_style;
|
if (self.menu.scrollbar) |scrollbar| scrollbar.style_factory = scrollbar_style;
|
||||||
self.longest_hint = if (@hasDecl(options, "load_entries_with_args"))
|
self.longest_hint = if (@hasDecl(options, "load_entries_with_args"))
|
||||||
try options.load_entries_with_args(self, ctx)
|
try options.load_entries_with_args(self, ctx)
|
||||||
else
|
else
|
||||||
try options.load_entries(self);
|
try options.load_entries(self);
|
||||||
|
if (self.entries.items.len > 0)
|
||||||
|
self.initial_selected = self.menu.selected;
|
||||||
if (@hasDecl(options, "restore_state"))
|
if (@hasDecl(options, "restore_state"))
|
||||||
options.restore_state(self) catch {};
|
options.restore_state(self) catch {};
|
||||||
if (@hasDecl(options, "initial_query")) blk: {
|
if (@hasDecl(options, "initial_query")) blk: {
|
||||||
|
|
@ -101,12 +109,7 @@ pub fn Create(options: type) type {
|
||||||
try self.start_query(0);
|
try self.start_query(0);
|
||||||
try mv.floating_views.add(self.modal.widget());
|
try mv.floating_views.add(self.modal.widget());
|
||||||
try mv.floating_views.add(self.menu.container_widget);
|
try mv.floating_views.add(self.menu.container_widget);
|
||||||
var mode = try keybind.mode("overlay/palette", allocator, .{
|
return self.mode;
|
||||||
.insert_command = "overlay_insert_bytes",
|
|
||||||
});
|
|
||||||
mode.event_handler = EventHandler.to_owned(self);
|
|
||||||
mode.name = options.name;
|
|
||||||
return mode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
(try palette.entries.addOne(palette.allocator)).* = .{ .label = try palette.allocator.dupe(u8, task) };
|
(try palette.entries.addOne(palette.allocator)).* = .{ .label = try palette.allocator.dupe(u8, task) };
|
||||||
longest = @max(longest, task.len);
|
longest = @max(longest, task.len);
|
||||||
}
|
}
|
||||||
const hints = if (tui.input_mode()) |m| m.keybind_hints else @panic("no keybind hints");
|
const hints = palette.mode.keybind_hints;
|
||||||
var longest_hint: usize = 0;
|
var longest_hint: usize = 0;
|
||||||
longest_hint = @max(longest_hint, try add_palette_command(palette, "add_task", hints));
|
longest_hint = @max(longest_hint, try add_palette_command(palette, "add_task", hints));
|
||||||
longest_hint = @max(longest_hint, try add_palette_command(palette, "palette_menu_delete_item", hints));
|
longest_hint = @max(longest_hint, try add_palette_command(palette, "palette_menu_delete_item", hints));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue