From 5224b6157cf02015057379f1891f90d1ccf5ac5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Dvo=C5=99=C3=A1k?= Date: Fri, 3 Nov 2023 18:28:34 +0100 Subject: [PATCH] fix: posToViewPort when using balanced padding enabled --- src/Surface.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 9b89f6618..8c0641ade 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -152,6 +152,7 @@ const DerivedConfig = struct { vt_kam_allowed: bool, window_padding_x: u32, window_padding_y: u32, + window_padding_balance: bool, pub fn init(alloc_gpa: Allocator, config: *const configpkg.Config) !DerivedConfig { var arena = ArenaAllocator.init(alloc_gpa); @@ -174,6 +175,7 @@ const DerivedConfig = struct { .vt_kam_allowed = config.@"vt-kam-allowed", .window_padding_x = config.@"window-padding-x", .window_padding_y = config.@"window-padding-y", + .window_padding_balance = config.@"window-padding-balance", // Assignments happen sequentially so we have to do this last // so that the memory is captured from allocs above. @@ -2107,8 +2109,13 @@ fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport { // amount from the renderer. This is a bug but realistically balanced // padding is so small it doesn't affect selection. This may not be true // at large font sizes... - const xpos_adjusted: f64 = xpos - @as(f64, @floatFromInt(self.padding.left)); - const ypos_adjusted: f64 = ypos - @as(f64, @floatFromInt(self.padding.top)); + const pad = if (self.config.window_padding_balance) + renderer.Padding.balanced(self.screen_size, self.grid_size, self.cell_size) + else + self.padding; + + const xpos_adjusted: f64 = xpos - @as(f64, @floatFromInt(pad.left)); + const ypos_adjusted: f64 = ypos - @as(f64, @floatFromInt(pad.top)); // xpos and ypos can be negative if while dragging, the user moves the // mouse off the surface. Likewise, they can be larger than our surface