diff --git a/src/Surface.zig b/src/Surface.zig index d111c3f2d..55fb89f7c 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2080,6 +2080,15 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !void try self.io_thread.wakeup.notify(); }, + .scroll_page_fractional => |fraction| { + const rows: f32 = @floatFromInt(self.grid_size.rows); + const delta: isize = @intFromFloat(@floor(fraction * rows)); + _ = self.io_thread.mailbox.push(.{ + .scroll_viewport = .{ .delta = delta }, + }, .{ .forever = {} }); + try self.io_thread.wakeup.notify(); + }, + .jump_to_prompt => |delta| { _ = self.io_thread.mailbox.push(.{ .jump_to_prompt = @intCast(delta), diff --git a/src/input/Binding.zig b/src/input/Binding.zig index a877daabf..46292ee90 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -132,6 +132,14 @@ pub fn parse(input: []const u8) !Binding { break :action @unionInit(Action, field.name, value); }, + .Float => { + const idx = colonIdx orelse return Error.InvalidFormat; + const param = actionRaw[idx + 1 ..]; + const value = std.fmt.parseFloat(field.type, param) catch + return Error.InvalidFormat; + break :action @unionInit(Action, field.name, value); + }, + else => unreachable, }, } @@ -182,6 +190,7 @@ pub const Action = union(enum) { scroll_to_bottom: void, scroll_page_up: void, scroll_page_down: void, + scroll_page_fractional: f32, /// Jump the viewport forward or back by prompt. Positive /// number is the number of prompts to jump forward, negative @@ -448,3 +457,19 @@ test "parse: action with int" { try testing.expectEqual(@as(i16, 10), binding.action.jump_to_prompt); } } + +test "parse: action with float" { + const testing = std.testing; + + // parameter + { + const binding = try parse("a=scroll_page_fractional:-0.5"); + try testing.expect(binding.action == .scroll_page_fractional); + try testing.expectEqual(@as(f32, -0.5), binding.action.scroll_page_fractional); + } + { + const binding = try parse("a=scroll_page_fractional:+0.5"); + try testing.expect(binding.action == .scroll_page_fractional); + try testing.expectEqual(@as(f32, 0.5), binding.action.scroll_page_fractional); + } +}