Add "Scroll to Selection" command

This commit is contained in:
fn ⌃ ⌥
2025-05-03 09:07:12 -07:00
committed by Mitchell Hashimoto
parent eb7368699b
commit 071531c5c5
3 changed files with 16 additions and 0 deletions

View File

@@ -4119,6 +4119,14 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
}, .unlocked);
},
.scroll_to_selection => {
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
const sel = self.io.terminal.screen.selection orelse return false;
const tl = sel.topLeft(&self.io.terminal.screen);
self.io.terminal.screen.scroll(.{ .pin = tl });
},
.scroll_page_up => {
const rows: isize = @intCast(self.size.grid().rows);
self.io.queueMessage(.{

View File

@@ -279,6 +279,7 @@ pub const Action = union(enum) {
/// Scroll the screen varying amounts.
scroll_to_top,
scroll_to_bottom,
scroll_to_selection,
scroll_page_up,
scroll_page_down,
scroll_page_fractional: f32,
@@ -789,6 +790,7 @@ pub const Action = union(enum) {
.select_all,
.scroll_to_top,
.scroll_to_bottom,
.scroll_to_selection,
.scroll_page_up,
.scroll_page_down,
.scroll_page_fractional,

View File

@@ -170,6 +170,12 @@ fn actionCommands(action: Action.Key) []const Command {
.description = "Scroll to the bottom of the screen.",
}},
.scroll_to_selection => comptime &.{.{
.action = .scroll_to_selection,
.title = "Scroll to Selection",
.description = "Scroll to the selected text.",
}},
.scroll_page_up => comptime &.{.{
.action = .scroll_page_up,
.title = "Scroll Page Up",