mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 00:36:07 +03:00
scroll top, bot, page up, page down binding actions
This commit is contained in:
@ -2050,6 +2050,36 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !void
|
||||
try self.io_thread.wakeup.notify();
|
||||
},
|
||||
|
||||
.scroll_to_top => {
|
||||
_ = self.io_thread.mailbox.push(.{
|
||||
.scroll_viewport = .{ .top = {} },
|
||||
}, .{ .forever = {} });
|
||||
try self.io_thread.wakeup.notify();
|
||||
},
|
||||
|
||||
.scroll_to_bottom => {
|
||||
_ = self.io_thread.mailbox.push(.{
|
||||
.scroll_viewport = .{ .bottom = {} },
|
||||
}, .{ .forever = {} });
|
||||
try self.io_thread.wakeup.notify();
|
||||
},
|
||||
|
||||
.scroll_page_up => {
|
||||
const rows: isize = @intCast(self.grid_size.rows);
|
||||
_ = self.io_thread.mailbox.push(.{
|
||||
.scroll_viewport = .{ .delta = -1 * rows },
|
||||
}, .{ .forever = {} });
|
||||
try self.io_thread.wakeup.notify();
|
||||
},
|
||||
|
||||
.scroll_page_down => {
|
||||
const rows: isize = @intCast(self.grid_size.rows);
|
||||
_ = self.io_thread.mailbox.push(.{
|
||||
.scroll_viewport = .{ .delta = rows },
|
||||
}, .{ .forever = {} });
|
||||
try self.io_thread.wakeup.notify();
|
||||
},
|
||||
|
||||
.jump_to_prompt => |delta| {
|
||||
_ = self.io_thread.mailbox.push(.{
|
||||
.jump_to_prompt = @intCast(delta),
|
||||
|
@ -489,6 +489,28 @@ pub const Config = struct {
|
||||
.{ .clear_screen = {} },
|
||||
);
|
||||
|
||||
// Viewport scrolling
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .home, .mods = .{ .super = true } },
|
||||
.{ .scroll_to_top = {} },
|
||||
);
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .end, .mods = .{ .super = true } },
|
||||
.{ .scroll_to_bottom = {} },
|
||||
);
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .page_up, .mods = .{ .super = true } },
|
||||
.{ .scroll_page_up = {} },
|
||||
);
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .page_down, .mods = .{ .super = true } },
|
||||
.{ .scroll_page_down = {} },
|
||||
);
|
||||
|
||||
// Semantic prompts
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
|
@ -177,6 +177,12 @@ pub const Action = union(enum) {
|
||||
/// Clear the screen. This also clears all scrollback.
|
||||
clear_screen: void,
|
||||
|
||||
/// Scroll the screen varying amounts.
|
||||
scroll_to_top: void,
|
||||
scroll_to_bottom: void,
|
||||
scroll_page_up: void,
|
||||
scroll_page_down: void,
|
||||
|
||||
/// Jump the viewport forward or back by prompt. Positive
|
||||
/// number is the number of prompts to jump forward, negative
|
||||
/// is backwards.
|
||||
|
@ -1460,6 +1460,7 @@ pub const ScrollViewport = union(enum) {
|
||||
/// Scroll to the bottom, i.e. the top of the active area
|
||||
bottom: void,
|
||||
|
||||
/// Scroll by some delta amount, up is negative.
|
||||
delta: isize,
|
||||
};
|
||||
|
||||
|
@ -300,6 +300,13 @@ pub fn clearScreen(self: *Exec, history: bool) !void {
|
||||
try self.queueWrite(&[_]u8{0x0C});
|
||||
}
|
||||
|
||||
/// Scroll the viewport
|
||||
pub fn scrollViewport(self: *Exec, scroll: terminal.Terminal.ScrollViewport) !void {
|
||||
self.renderer_state.mutex.lock();
|
||||
defer self.renderer_state.mutex.unlock();
|
||||
try self.terminal.scrollViewport(scroll);
|
||||
}
|
||||
|
||||
/// Jump the viewport to the prompt.
|
||||
pub fn jumpToPrompt(self: *Exec, delta: isize) !void {
|
||||
const wakeup: bool = wakeup: {
|
||||
|
@ -156,6 +156,7 @@ fn drainMailbox(self: *Thread) !void {
|
||||
},
|
||||
.resize => |v| self.handleResize(v),
|
||||
.clear_screen => |v| try self.impl.clearScreen(v.history),
|
||||
.scroll_viewport => |v| try self.impl.scrollViewport(v),
|
||||
.jump_to_prompt => |v| try self.impl.jumpToPrompt(v),
|
||||
.write_small => |v| try self.impl.queueWrite(v.data[0..v.len]),
|
||||
.write_stable => |v| try self.impl.queueWrite(v),
|
||||
|
@ -45,6 +45,9 @@ pub const Message = union(enum) {
|
||||
history: bool,
|
||||
},
|
||||
|
||||
/// Scroll the viewport
|
||||
scroll_viewport: terminal.Terminal.ScrollViewport,
|
||||
|
||||
/// Jump forward/backward n prompts.
|
||||
jump_to_prompt: isize,
|
||||
|
||||
|
Reference in New Issue
Block a user