fix: don't add fallback keybindings if they are overridden
This commit is contained in:
parent
b9b3d21189
commit
ed2be3767a
1 changed files with 17 additions and 2 deletions
|
@ -110,6 +110,9 @@ fn current_namespace() *const Namespace {
|
||||||
fn get_or_load_namespace(namespace_name: []const u8) LoadError!*const Namespace {
|
fn get_or_load_namespace(namespace_name: []const u8) LoadError!*const Namespace {
|
||||||
const allocator = globals_allocator;
|
const allocator = globals_allocator;
|
||||||
return globals.namespaces.getPtr(namespace_name) orelse blk: {
|
return globals.namespaces.getPtr(namespace_name) orelse blk: {
|
||||||
|
const logger = log.logger("keybind");
|
||||||
|
logger.print("loading namespace '{s}'", .{namespace_name});
|
||||||
|
defer logger.deinit();
|
||||||
const namespace = try Namespace.load(allocator, namespace_name);
|
const namespace = try Namespace.load(allocator, namespace_name);
|
||||||
const result = try globals.namespaces.getOrPut(allocator, try allocator.dupe(u8, namespace_name));
|
const result = try globals.namespaces.getOrPut(allocator, try allocator.dupe(u8, namespace_name));
|
||||||
std.debug.assert(result.found_existing == false);
|
std.debug.assert(result.found_existing == false);
|
||||||
|
@ -370,8 +373,8 @@ const BindingSet = struct {
|
||||||
try self.load_event(allocator, &self.press, input.event.press, parsed.value.press);
|
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);
|
try self.load_event(allocator, &self.release, input.event.release, parsed.value.release);
|
||||||
if (fallback) |fallback_| {
|
if (fallback) |fallback_| {
|
||||||
for (fallback_.press.items) |binding| try self.press.append(allocator, binding);
|
for (fallback_.press.items) |binding| try append_if_not_match(allocator, &self.press, binding);
|
||||||
for (fallback_.release.items) |binding| try self.release.append(allocator, binding);
|
for (fallback_.release.items) |binding| try append_if_not_match(allocator, &self.release, binding);
|
||||||
}
|
}
|
||||||
self.build_hints(allocator) catch {};
|
self.build_hints(allocator) catch {};
|
||||||
return self;
|
return self;
|
||||||
|
@ -444,6 +447,18 @@ const BindingSet = struct {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn append_if_not_match(
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
|
dest: *std.ArrayListUnmanaged(Binding),
|
||||||
|
new_binding: Binding,
|
||||||
|
) error{OutOfMemory}!void {
|
||||||
|
for (dest.items) |*binding| switch (binding.match(new_binding.key_events)) {
|
||||||
|
.matched, .match_possible => return,
|
||||||
|
.match_impossible => {},
|
||||||
|
};
|
||||||
|
try dest.append(allocator, new_binding);
|
||||||
|
}
|
||||||
|
|
||||||
fn hints(self: *const @This()) *const KeybindHints {
|
fn hints(self: *const @This()) *const KeybindHints {
|
||||||
return &self.hints_map;
|
return &self.hints_map;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue