-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(terminal): reflow surviving panes after split changes #12835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
austinywang
wants to merge
22
commits into
main
Choose a base branch
from
issue-12381-split-reflow-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fe3c6d0
test: cover terminal cell metrics across split reflow
austinywang 6723ce0
test: reproduce lost resize completion and Retina metrics
austinywang cf83c2a
fix: reconcile terminal metrics and finish inactive pane resizes
austinywang 5bbe5e7
test: yield actor execution while terminal geometry settles
austinywang 961ec1a
test: initialize AppKit before pane fixture setup
austinywang c23d91b
test: read physical viewport rows and await divider completion
austinywang 959f16c
test: inspect native grid spans for physical reflow
austinywang 5209dd7
test: assert exported native cell widths directly
austinywang caba6aa
test: satisfy required deinit lint
austinywang dc8c649
Merge main and integrate metric invalidation with committed geometry
austinywang 9f104a3
Merge remote-tracking branch 'origin/main' into issue-12381-split-ref…
austinywang 80a9571
fix: restore test target membership after main merge
austinywang e1c70e2
fix: restore metrics test target membership
austinywang 8f2fe4a
fix: restore app source membership after main merge
austinywang d2f5400
Merge remote-tracking branch 'origin/main' into issue-12381-split-ref…
austinywang 32e8414
Merge remote-tracking branch 'origin/main' into issue-12381-split-ref…
austinywang 7a36721
test: preserve logical markers through hidden pane reflow
austinywang 1aa71cc
test: preserve soft-wrapped terminal markers
austinywang 9f8760a
Merge remote-tracking branch 'origin/main' into issue-12381-split-ref…
austinywang db5d7a7
test: read reflow markers from the viewport
austinywang 2001e75
Merge origin/main into issue-12381-split-reflow-metrics
austinywang 3a713d6
Normalize Xcode project after main merge
austinywang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import AppKit | ||
| import CmuxTerminal | ||
|
|
||
| extension GhosttyNSView { | ||
| /// Invalidates a queued metric snapshot by reading the current runtime. | ||
| /// Ghostty reports backing pixels; AppKit scrolling and hit testing use points. | ||
| @discardableResult | ||
| func synchronizeCellMetrics() -> Bool { | ||
| guard let size = terminalSurface?.cellSizePoints(), | ||
| size.width.isFinite, size.height.isFinite, | ||
| size.width > 0, size.height > 0, | ||
| cellSize != size else { return false } | ||
| cellSize = size | ||
| NotificationCenter.default.post( | ||
| name: .ghosttyDidUpdateCellSize, | ||
| object: self, | ||
| userInfo: [GhosttyNotificationKey.cellSize: size] | ||
| ) | ||
| return true | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5454,7 +5454,7 @@ class GhosttyNSView: NSView, NSUserInterfaceValidations { | |
| layer?.masksToBounds = true | ||
| let didChangeDrawable = applyDrawableGeometry(geometry) | ||
| let surfaceSizeChanged = terminalSurface.commitPaneGeometry(geometry) | ||
| return didChangeDrawable || surfaceSizeChanged | ||
| return synchronizeCellMetrics() || didChangeDrawable || surfaceSizeChanged | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: A queued Prompt for AI agents |
||
| } | ||
|
|
||
| /// Re-applies the current pane size: the committed geometry for a | ||
|
|
@@ -5468,7 +5468,7 @@ class GhosttyNSView: NSView, NSUserInterfaceValidations { | |
| guard let geometry = terminalSurface.committedPaneGeometry else { return false } | ||
| let didChangeDrawable = applyDrawableGeometry(geometry) | ||
| let surfaceSizeChanged = terminalSurface.reapplyCommittedPaneGeometry() | ||
| return didChangeDrawable || surfaceSizeChanged | ||
| return synchronizeCellMetrics() || didChangeDrawable || surfaceSizeChanged | ||
| } | ||
| return commitOwnBounds() | ||
| } | ||
|
|
@@ -13687,7 +13687,7 @@ final class GhosttySurfaceScrollView: NSView { | |
| // publishes its inner frame here. | ||
| if surfaceView.paneGeometryIsPortalOwned { | ||
| paneGeometryPortal?.requestPaneGeometryCommit(for: self) | ||
| return false | ||
| return surfaceView.synchronizeCellMetrics() | ||
| } | ||
| return surfaceView.commitPaneGeometry( | ||
| size: CGSize(width: width, height: height), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| import AppKit | ||
| import CmuxTerminal | ||
| import GhosttyKit | ||
| import Testing | ||
|
|
||
| #if canImport(cmux_DEV) | ||
| @testable import cmux_DEV | ||
| #elseif canImport(cmux) | ||
| @testable import cmux | ||
| #endif | ||
|
|
||
| @MainActor | ||
| @Suite(.serialized) | ||
| struct TerminalPaneMetricInvalidationTests { | ||
| @Test(arguments: [CGFloat(1), CGFloat(2)]) | ||
| func fontCallbacksUseCurrentLogicalCellSize(backingScale: CGFloat) async throws { | ||
| let fixture = try await TerminalPaneMetricsFixture(backingScale: backingScale) | ||
| defer { fixture.tearDown() } | ||
| try await fixture.bind() | ||
| #expect(fixture.surface.performInternalBindingAction("set_font_size:24")) | ||
| #expect(fixture.surface.performInternalBindingAction("set_font_size:13")) | ||
| try await fixture.waitUntil("logical cell metrics") { | ||
| fixture.hosted.surfaceView.cellSize == fixture.surface.cellSizePoints() | ||
| } | ||
| let sample = try #require(fixture.surface.rawSizingSample()) | ||
| #expect(fixture.hosted.surfaceView.cellSize.width == CGFloat(sample.cellWidthPx) / backingScale) | ||
| #expect(fixture.hosted.surfaceView.cellSize.height == CGFloat(sample.cellHeightPx) / backingScale) | ||
| } | ||
|
|
||
| @Test(arguments: [CGFloat(1), CGFloat(2)]) | ||
| func hiddenOutputReflowsThroughDividerDragAndSplitClose(backingScale: CGFloat) async throws { | ||
| let fixture = try await TerminalPaneMetricsFixture(backingScale: backingScale) | ||
| defer { fixture.tearDown() } | ||
| // The original #12381 path: output arrives before the split is shown. | ||
| try fixture.writeRows() | ||
| try await fixture.bind() | ||
| let originalCell = try #require(fixture.surface.cellSizePoints()) | ||
| let originalFont = ghostty_surface_font_size(try #require(fixture.surface.surface)) | ||
| for width: CGFloat in [280, 620, 360] { | ||
| try await fixture.moveDivider(to: width) | ||
| try assertGridAndText(fixture, cell: originalCell, font: originalFont) | ||
| } | ||
| try await fixture.closeSibling() | ||
| try assertGridAndText(fixture, cell: originalCell, font: originalFont) | ||
| } | ||
|
|
||
| @Test func paneGeometryInvalidatesStaleLargerCellMetrics() async throws { | ||
| let fixture = try await TerminalPaneMetricsFixture() | ||
| defer { fixture.tearDown() } | ||
| try await fixture.bind() | ||
| let expected = try #require(fixture.surface.cellSizePoints()) | ||
| // Simulate a delayed metric notification from the previous layout. | ||
| // Repair must come from each pane geometry boundary, with no window | ||
| // resize, config reload, or font-size mutation. | ||
| for closeSibling in [false, true] { | ||
| fixture.hosted.surfaceView.cellSize = CGSize(width: expected.width * 2, height: expected.height * 2) | ||
| if closeSibling { try await fixture.closeSibling() } | ||
| else { try await fixture.moveDivider(to: 340) } | ||
| #expect(fixture.hosted.surfaceView.cellSize == expected) | ||
| } | ||
| } | ||
|
|
||
| @Test func sameFrameReconciliationRepairsMetricCache() async throws { | ||
| let fixture = try await TerminalPaneMetricsFixture() | ||
| defer { fixture.tearDown() } | ||
| try await fixture.bind() | ||
| let expected = try #require(fixture.surface.cellSizePoints()) | ||
| let frame = fixture.hosted.frame | ||
| fixture.hosted.surfaceView.cellSize = CGSize(width: expected.width * 2, height: expected.height * 2) | ||
| _ = fixture.hosted.reconcileGeometryNow() | ||
| #expect(fixture.hosted.frame == frame) | ||
| #expect(fixture.hosted.surfaceView.cellSize == expected) | ||
| } | ||
|
|
||
| @Test func splitCloseRecoversAfterNativeResizeEndCallbackWasLost() async throws { | ||
| let fixture = try await TerminalPaneMetricsFixture() | ||
| defer { fixture.tearDown() } | ||
| try await fixture.bind() | ||
| let portal = try #require(TerminalWindowPortalRegistry.portalsByWindowId[ObjectIdentifier(fixture.window)]) | ||
| portal.isWindowLiveResizeActiveOverrideForTesting = true | ||
| defer { portal.isWindowLiveResizeActiveOverrideForTesting = false } | ||
| fixture.split.setPosition(320, ofDividerAt: 0) | ||
| TerminalWindowPortalRegistry.synchronizeForAnchor(fixture.anchor, syncLayout: false) | ||
| #expect(fixture.surface.committedPaneGeometry?.phase == .interactive) | ||
| portal.isWindowLiveResizeActiveOverrideForTesting = false | ||
| // No window notification: only the surviving pane's layout changes. | ||
| try await fixture.closeSibling() | ||
| #expect(fixture.surface.committedPaneGeometry?.phase == .settled) | ||
| } | ||
|
|
||
| @Test func activeDividerDoesNotFinishWhenNativeWindowResizeIsInactive() async throws { | ||
| let fixture = try await TerminalPaneMetricsFixture() | ||
| defer { fixture.tearDown() } | ||
| try await fixture.bind() | ||
| TerminalWindowPortalRegistry.beginInteractiveGeometryResize(in: fixture.window) | ||
| var dividerActive = true | ||
| defer { | ||
| if dividerActive { TerminalWindowPortalRegistry.endInteractiveGeometryResize(in: fixture.window) } | ||
| } | ||
| fixture.split.setPosition(320, ofDividerAt: 0) | ||
| TerminalWindowPortalRegistry.synchronizeExternalGeometryNow(for: fixture.window) | ||
| #expect(fixture.surface.committedPaneGeometry?.phase == .interactive) | ||
| TerminalWindowPortalRegistry.endInteractiveGeometryResize(in: fixture.window) | ||
| dividerActive = false | ||
| try await fixture.settle() | ||
| #expect(fixture.surface.committedPaneGeometry?.phase == .settled) | ||
| } | ||
|
|
||
| private func assertGridAndText(_ fixture: TerminalPaneMetricsFixture, cell: CGSize, font: Float) throws { | ||
| let sample = try #require(fixture.surface.rawSizingSample()) | ||
| let runtime = try #require(fixture.surface.surface) | ||
| var grid = ghostty_surface_grid_metrics_s() | ||
| #expect(ghostty_surface_grid_metrics(runtime, &grid)) | ||
| #expect(Int(grid.columns) == sample.columns) | ||
| #expect(Int(grid.rows) == sample.rows) | ||
| #expect(fixture.surface.cellSizePoints() == cell) | ||
| #expect(fixture.hosted.surfaceView.cellSize == cell) | ||
| #expect(ghostty_surface_font_size(runtime) == font) | ||
| // Text selection unwraps soft-wrapped lines even for rectangles. | ||
| // Inspect the native grid export, including each span's cell extent. | ||
| let rendered = try #require(fixture.surface.mobileRenderGridFrame(stateSeq: 0, includeTheme: false)) | ||
| #expect(rendered.frame.columns == sample.columns) | ||
| #expect(rendered.frame.rows == sample.rows) | ||
| for span in rendered.frame.rowSpans { | ||
| let cellWidth = try #require(span.cellWidth) | ||
| #expect(span.row < sample.rows) | ||
| #expect(span.column + cellWidth <= sample.columns) | ||
| } | ||
| #expect(rendered.rows.allSatisfy { $0.count <= sample.columns }) | ||
| // The native render-grid export is the physical reflow oracle above, | ||
| // but it can omit soft-wrapped text while a hidden pane is settling. | ||
| // Ghostty's direct reader preserves those logical lines and their | ||
| // markers, which is the behavior this regression path needs to prove. | ||
| let text = try readSurfaceText(fixture) | ||
| let compact = text.filter { !$0.isWhitespace } | ||
| for index in 1...4 { | ||
| let expected = "R\(index)" + String(repeating: "=", count: 74) + "END\(index)" | ||
| #expect(compact.components(separatedBy: expected).count == 2) | ||
| #expect(compact.components(separatedBy: "R\(index)").count == 2) | ||
| #expect(compact.components(separatedBy: "END\(index)").count == 2) | ||
| } | ||
| } | ||
|
|
||
| private func readSurfaceText(_ fixture: TerminalPaneMetricsFixture) throws -> String { | ||
| let runtime = try #require(fixture.surface.surface) | ||
| let selection = ghostty_selection_s( | ||
| top_left: ghostty_point_s( | ||
| tag: GHOSTTY_POINT_VIEWPORT, | ||
| coord: GHOSTTY_POINT_COORD_TOP_LEFT, | ||
| x: 0, | ||
| y: 0 | ||
| ), | ||
| bottom_right: ghostty_point_s( | ||
| tag: GHOSTTY_POINT_VIEWPORT, | ||
| coord: GHOSTTY_POINT_COORD_BOTTOM_RIGHT, | ||
| x: 0, | ||
| y: 0 | ||
| ), | ||
| rectangle: true | ||
| ) | ||
| var text = ghostty_text_s() | ||
| guard ghostty_surface_read_text(runtime, selection, &text) else { return "" } | ||
| defer { ghostty_surface_free_text(runtime, &text) } | ||
| guard let pointer = text.text, text.text_len > 0 else { return "" } | ||
| return String( | ||
| decoding: Data(bytes: pointer, count: Int(text.text_len)), | ||
| as: UTF8.self | ||
| ) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.