diff --git a/src/input/Binding.zig b/src/input/Binding.zig index 6bb50fc5d..6583e1462 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -568,6 +568,8 @@ pub const Action = union(enum) { left, up, auto, // splits along the larger direction + + pub const default: SplitDirection = .auto; }; pub const SplitFocusDirection = enum { @@ -729,7 +731,28 @@ pub const Action = union(enum) { Action.CursorKey => return Error.InvalidAction, else => { - const idx = colonIdx orelse return Error.InvalidFormat; + // Get the parameter after the colon. The parameter + // can be optional for action types that can have a + // "default" decl. + const idx = colonIdx orelse { + switch (@typeInfo(field.type)) { + .@"struct", + .@"union", + .@"enum", + => if (@hasDecl(field.type, "default")) { + return @unionInit( + Action, + field.name, + @field(field.type, "default"), + ); + }, + + else => {}, + } + + return Error.InvalidFormat; + }; + const param = input[idx + 1 ..]; return @unionInit( Action, @@ -2015,6 +2038,17 @@ test "parse: action with enum" { } } +test "parse: action with enum with default" { + const testing = std.testing; + + // parameter + { + const binding = try parseSingle("a=new_split"); + try testing.expect(binding.action == .new_split); + try testing.expectEqual(Action.SplitDirection.auto, binding.action.new_split); + } +} + test "parse: action with int" { const testing = std.testing;