Merge pull request #806 from dvorakluk/fix/balanced-pointToViewport

fix: posToViewPort when balanced padding enabled
This commit is contained in:
Mitchell Hashimoto
2023-11-03 14:15:13 -07:00
committed by GitHub

View File

@ -152,6 +152,7 @@ const DerivedConfig = struct {
vt_kam_allowed: bool, vt_kam_allowed: bool,
window_padding_x: u32, window_padding_x: u32,
window_padding_y: u32, window_padding_y: u32,
window_padding_balance: bool,
pub fn init(alloc_gpa: Allocator, config: *const configpkg.Config) !DerivedConfig { pub fn init(alloc_gpa: Allocator, config: *const configpkg.Config) !DerivedConfig {
var arena = ArenaAllocator.init(alloc_gpa); var arena = ArenaAllocator.init(alloc_gpa);
@ -174,6 +175,7 @@ const DerivedConfig = struct {
.vt_kam_allowed = config.@"vt-kam-allowed", .vt_kam_allowed = config.@"vt-kam-allowed",
.window_padding_x = config.@"window-padding-x", .window_padding_x = config.@"window-padding-x",
.window_padding_y = config.@"window-padding-y", .window_padding_y = config.@"window-padding-y",
.window_padding_balance = config.@"window-padding-balance",
// Assignments happen sequentially so we have to do this last // Assignments happen sequentially so we have to do this last
// so that the memory is captured from allocs above. // so that the memory is captured from allocs above.
@ -2102,13 +2104,14 @@ fn dragLeftClickSingle(
fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport { fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport {
// xpos/ypos need to be adjusted for window padding // xpos/ypos need to be adjusted for window padding
// (i.e. "window-padding-*" settings. NOTE we don't adjust for // (i.e. "window-padding-*" settings.
// "window-padding-balance" because we don't have access to the balance const pad = if (self.config.window_padding_balance)
// amount from the renderer. This is a bug but realistically balanced renderer.Padding.balanced(self.screen_size, self.grid_size, self.cell_size)
// padding is so small it doesn't affect selection. This may not be true else
// at large font sizes... self.padding;
const xpos_adjusted: f64 = xpos - @as(f64, @floatFromInt(self.padding.left));
const ypos_adjusted: f64 = ypos - @as(f64, @floatFromInt(self.padding.top)); 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 // 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 // mouse off the surface. Likewise, they can be larger than our surface