From 88444d4bd768f92effe971784d6b50b44dab0670 Mon Sep 17 00:00:00 2001 From: Daniel Wennberg Date: Tue, 21 Oct 2025 13:01:22 -0700 Subject: [PATCH] macOS: Adjust documentView padding on layout changes --- macos/Sources/Ghostty/SurfaceScrollView.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/macos/Sources/Ghostty/SurfaceScrollView.swift b/macos/Sources/Ghostty/SurfaceScrollView.swift index 08d249c4e..2a9e49d9a 100644 --- a/macos/Sources/Ghostty/SurfaceScrollView.swift +++ b/macos/Sources/Ghostty/SurfaceScrollView.swift @@ -174,10 +174,19 @@ class SurfaceScrollView: NSView { } } - // Keep document width synchronized with content width + // Keep document width synchronized with content width, and + // recalculate the height of the document view to account for the + // change in padding around the cell grid due to the resize. + var documentHeight = documentView.frame.height + let cellHeight = surfaceView.cellSize.height + if cellHeight > 0 { + let oldPadding = fmod(documentHeight, cellHeight) + let newPadding = fmod(contentSize.height, cellHeight) + documentHeight += newPadding - oldPadding + } documentView.setFrameSize(CGSize( width: contentSize.width, - height: documentView.frame.height + height: documentHeight )) // Inform the actual pty of our size change. This doesn't change the actual view @@ -261,8 +270,7 @@ class SurfaceScrollView: NSView { // The full document height must include the vertical padding around the cell // grid, otherwise the content view ends up misaligned with the surface. let documentGridHeight = CGFloat(scrollbar.total) * cellHeight - let gridHeight = CGFloat(scrollbar.len) * cellHeight - let padding = scrollView.contentSize.height - gridHeight + let padding = fmod(scrollView.contentSize.height, cellHeight) let documentHeight = documentGridHeight + padding // Our width should be the content width to account for visible scrollers.