feat: always add a toggle_input_mode keybinding (f2)

Even if it is not configured for the mode. This allows the user to switch
to the next mode even if the mode could not be loaded/parsed properly.
This commit is contained in:
CJ van den Berg 2024-11-18 19:30:15 +01:00
parent 22fdff4543
commit 031d57a54d
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -206,6 +206,11 @@ const BindingSet = struct {
} }
fn load_json(self: *@This(), json_string: []const u8, namespace_name: []const u8, mode_name: []const u8) !void { fn load_json(self: *@This(), json_string: []const u8, namespace_name: []const u8, mode_name: []const u8) !void {
defer self.bindings.append(.{
.keys = self.allocator.dupe(KeyEvent, &[_]KeyEvent{.{ .key = input.key.f2 }}) catch @panic("failed to add toggle_input_mode fallback"),
.command = self.allocator.dupe(u8, "toggle_input_mode") catch @panic("failed to add toggle_input_mode fallback"),
.args = "",
}) catch {};
const parsed = try std.json.parseFromSlice(std.json.Value, self.allocator, json_string, .{}); const parsed = try std.json.parseFromSlice(std.json.Value, self.allocator, json_string, .{});
defer parsed.deinit(); defer parsed.deinit();
if (parsed.value != .object) return error.NotAnObject; if (parsed.value != .object) return error.NotAnObject;