feat: generate hints for dynamic keybindings
This commit is contained in:
parent
271f45e78a
commit
3af2b09891
10 changed files with 98 additions and 64 deletions
|
@ -48,12 +48,14 @@ pub fn Create(options: type) type {
|
|||
try options.load_entries(self);
|
||||
if (@hasDecl(options, "restore_state"))
|
||||
options.restore_state(self) catch {};
|
||||
const input_handler, const keybind_hints = try keybind.mode.mini.file_browser.create(allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
});
|
||||
return .{
|
||||
.{
|
||||
.input_handler = try keybind.mode.mini.file_browser.create(allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
}),
|
||||
.input_handler = input_handler,
|
||||
.event_handler = EventHandler.to_owned(self),
|
||||
.keybind_hints = keybind_hints,
|
||||
},
|
||||
.{
|
||||
.name = options.name(self),
|
||||
|
|
|
@ -44,12 +44,14 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.
|
|||
defer self.allocator.free(text);
|
||||
try self.input.appendSlice(text);
|
||||
}
|
||||
const input_handler, const keybind_hints = try keybind.mode.mini.find.create(allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
});
|
||||
return .{
|
||||
.{
|
||||
.input_handler = try keybind.mode.mini.find.create(allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
}),
|
||||
.input_handler = input_handler,
|
||||
.event_handler = EventHandler.to_owned(self),
|
||||
.keybind_hints = keybind_hints,
|
||||
},
|
||||
.{
|
||||
.name = name,
|
||||
|
|
|
@ -38,12 +38,14 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.
|
|||
@memcpy(self.buf[0..text.len], text);
|
||||
self.input = self.buf[0..text.len];
|
||||
};
|
||||
const input_handler, const keybind_hints = try keybind.mode.mini.find_in_files.create(allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
});
|
||||
return .{
|
||||
.{
|
||||
.input_handler = try keybind.mode.mini.find_in_files.create(allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
}),
|
||||
.input_handler = input_handler,
|
||||
.event_handler = EventHandler.to_owned(self),
|
||||
.keybind_hints = keybind_hints,
|
||||
},
|
||||
.{
|
||||
.name = name,
|
||||
|
|
|
@ -32,12 +32,14 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui.
|
|||
.start = editor.get_primary().cursor.row + 1,
|
||||
};
|
||||
try self.commands.init(self);
|
||||
const input_handler, const keybind_hints = try keybind.mode.mini.goto.create(allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
});
|
||||
return .{
|
||||
.{
|
||||
.input_handler = try keybind.mode.mini.goto.create(allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
}),
|
||||
.input_handler = input_handler,
|
||||
.event_handler = EventHandler.to_owned(self),
|
||||
.keybind_hints = keybind_hints,
|
||||
},
|
||||
.{
|
||||
.name = name,
|
||||
|
|
|
@ -41,12 +41,14 @@ pub fn create(allocator: Allocator, ctx: command.Context) !struct { tui.Mode, tu
|
|||
.operation = if (select) .select else .move,
|
||||
};
|
||||
try self.commands.init(self);
|
||||
const input_handler, const keybind_hints = try keybind.mode.mini.move_to_char.create(allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
});
|
||||
return .{
|
||||
.{
|
||||
.input_handler = try keybind.mode.mini.move_to_char.create(allocator, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
}),
|
||||
.input_handler = input_handler,
|
||||
.event_handler = EventHandler.to_owned(self),
|
||||
.keybind_hints = keybind_hints,
|
||||
},
|
||||
.{
|
||||
.name = self.name(),
|
||||
|
|
|
@ -59,11 +59,13 @@ pub fn create(allocator: std.mem.Allocator) !tui.Mode {
|
|||
self.menu.resize(.{ .y = 0, .x = self.menu_pos_x(), .w = max_menu_width() + 2 });
|
||||
try mv.floating_views.add(self.modal.widget());
|
||||
try mv.floating_views.add(self.menu.container_widget);
|
||||
const input_handler, const keybind_hints = try keybind.mode.overlay.palette.create(allocator, .{
|
||||
.insert_command = "overlay_insert_bytes",
|
||||
});
|
||||
return .{
|
||||
.input_handler = try keybind.mode.overlay.palette.create(allocator, .{
|
||||
.insert_command = "overlay_insert_bytes",
|
||||
}),
|
||||
.input_handler = input_handler,
|
||||
.event_handler = EventHandler.to_owned(self),
|
||||
.keybind_hints = keybind_hints,
|
||||
.name = " open recent",
|
||||
};
|
||||
}
|
||||
|
|
|
@ -71,8 +71,9 @@ pub fn Create(options: type) type {
|
|||
};
|
||||
self.menu.scrollbar.?.style_factory = scrollbar_style;
|
||||
if (self.hints) |hints| {
|
||||
for (hints.values()) |val|
|
||||
self.longest_hint = @max(self.longest_hint, val.len);
|
||||
var iter = hints.iterator();
|
||||
while (iter.next()) |p|
|
||||
self.longest_hint = @max(self.longest_hint, p.value_ptr.len);
|
||||
}
|
||||
try options.load_entries(self);
|
||||
if (@hasDecl(options, "restore_state"))
|
||||
|
@ -81,11 +82,13 @@ pub fn Create(options: type) type {
|
|||
try self.start_query();
|
||||
try mv.floating_views.add(self.modal.widget());
|
||||
try mv.floating_views.add(self.menu.container_widget);
|
||||
const input_handler, const keybind_hints = try keybind.mode.overlay.palette.create(allocator, .{
|
||||
.insert_command = "overlay_insert_bytes",
|
||||
});
|
||||
return .{
|
||||
.input_handler = try keybind.mode.overlay.palette.create(allocator, .{
|
||||
.insert_command = "overlay_insert_bytes",
|
||||
}),
|
||||
.input_handler = input_handler,
|
||||
.event_handler = EventHandler.to_owned(self),
|
||||
.keybind_hints = keybind_hints,
|
||||
.name = options.name,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue