mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
scroll_page_fractional keybinding
This commit is contained in:
@ -2080,6 +2080,15 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !void
|
|||||||
try self.io_thread.wakeup.notify();
|
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| {
|
.jump_to_prompt => |delta| {
|
||||||
_ = self.io_thread.mailbox.push(.{
|
_ = self.io_thread.mailbox.push(.{
|
||||||
.jump_to_prompt = @intCast(delta),
|
.jump_to_prompt = @intCast(delta),
|
||||||
|
@ -132,6 +132,14 @@ pub fn parse(input: []const u8) !Binding {
|
|||||||
break :action @unionInit(Action, field.name, value);
|
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,
|
else => unreachable,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -182,6 +190,7 @@ pub const Action = union(enum) {
|
|||||||
scroll_to_bottom: void,
|
scroll_to_bottom: void,
|
||||||
scroll_page_up: void,
|
scroll_page_up: void,
|
||||||
scroll_page_down: void,
|
scroll_page_down: void,
|
||||||
|
scroll_page_fractional: f32,
|
||||||
|
|
||||||
/// Jump the viewport forward or back by prompt. Positive
|
/// Jump the viewport forward or back by prompt. Positive
|
||||||
/// number is the number of prompts to jump forward, negative
|
/// 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);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user