feat(keybind): add inherits keybind config option for multiple inheritance

closes #189
This commit is contained in:
CJ van den Berg 2025-02-24 21:44:56 +01:00
parent 9145637134
commit 65a3e50b43
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -386,6 +386,7 @@ const BindingSet = struct {
line_numbers: LineNumbers = .inherit,
cursor: ?CursorShape = null,
inherit: ?[]const u8 = null,
inherits: ?[][]const u8 = null,
selection: ?SelectionStyle = null,
};
const parsed = try std.json.parseFromValue(JsonConfig, allocator, mode_bindings, .{
@ -400,7 +401,12 @@ const BindingSet = struct {
self.selection_style = parsed.value.selection orelse .normal;
try self.load_event(allocator, &self.press, input.event.press, parsed.value.press);
try self.load_event(allocator, &self.release, input.event.release, parsed.value.release);
if (parsed.value.inherit) |sibling_fallback| {
if (parsed.value.inherits) |sibling_fallbacks| {
for (sibling_fallbacks) |sibling_fallback| if (namespace.get_mode(sibling_fallback)) |sib| {
for (sib.press.items) |binding| try append_if_not_match(allocator, &self.press, binding);
for (sib.release.items) |binding| try append_if_not_match(allocator, &self.release, binding);
};
} else if (parsed.value.inherit) |sibling_fallback| {
if (namespace.get_mode(sibling_fallback)) |sib| {
for (sib.press.items) |binding| try append_if_not_match(allocator, &self.press, binding);
for (sib.release.items) |binding| try append_if_not_match(allocator, &self.release, binding);