Skip to content

Commit d40321a

Browse files
authored
macOS: Adjust documentView padding on layout changes (#9296)
Fixes a bug described in #9291, where resizing an empty window causes the scrollbar to appear even though the window remains larger than the total content, because the relayouting fails to account for the change in padding around the cell grid. To reproduce the issue: 1. Enable legacy scrollbars (System Settings -> Appearance -> Show scroll bars -> Always) 2. Open Ghostty 3. Vertically resize the window to make it smaller. The scrollbar will pop up, and as you drag the window edge, it will cycle between a maximum offset and zero depending on how far the resize is from an integer multiple of the cell height. With this PR you'll still see the scrollbar flicker while resizing, but when you stop it will always disappear. Haven't figured out how to get rid of the flickering yet. I tried to condition various updates on the window not being in a live resize, but so far no luck.
2 parents 86ec292 + 88444d4 commit d40321a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

macos/Sources/Ghostty/SurfaceScrollView.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,19 @@ class SurfaceScrollView: NSView {
174174
}
175175
}
176176

177-
// Keep document width synchronized with content width
177+
// Keep document width synchronized with content width, and
178+
// recalculate the height of the document view to account for the
179+
// change in padding around the cell grid due to the resize.
180+
var documentHeight = documentView.frame.height
181+
let cellHeight = surfaceView.cellSize.height
182+
if cellHeight > 0 {
183+
let oldPadding = fmod(documentHeight, cellHeight)
184+
let newPadding = fmod(contentSize.height, cellHeight)
185+
documentHeight += newPadding - oldPadding
186+
}
178187
documentView.setFrameSize(CGSize(
179188
width: contentSize.width,
180-
height: documentView.frame.height
189+
height: documentHeight
181190
))
182191

183192
// Inform the actual pty of our size change. This doesn't change the actual view
@@ -261,8 +270,7 @@ class SurfaceScrollView: NSView {
261270
// The full document height must include the vertical padding around the cell
262271
// grid, otherwise the content view ends up misaligned with the surface.
263272
let documentGridHeight = CGFloat(scrollbar.total) * cellHeight
264-
let gridHeight = CGFloat(scrollbar.len) * cellHeight
265-
let padding = scrollView.contentSize.height - gridHeight
273+
let padding = fmod(scrollView.contentSize.height, cellHeight)
266274
let documentHeight = documentGridHeight + padding
267275

268276
// Our width should be the content width to account for visible scrollers.

0 commit comments

Comments
 (0)