Repository navigation
Bound overflowing confirmation dialog content #8296
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0ddca24
Add failing bulk-close dialog overflow regression test
austinywang 22f5194
Bound user-sized confirmation dialog content
austinywang d40797d
Merge remote-tracking branch 'origin/main' into issue-8295-close-dial…
austinywang 5740ef2
Fix alert details height measurement
austinywang 77d6614
Reuse measured alert details view
austinywang 4108017
Address confirmation dialog review feedback
austinywang 648b395
Separate trailing alert details safely
austinywang 018e3d1
Merge remote-tracking branch 'origin/main' into issue-8295-close-dial…
austinywang 33e9d74
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang 0b3a8ab
Address modal alert review feedback
austinywang 0d07477
Use shared alert window resolution
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
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,94 @@ | ||
| import AppKit | ||
|
|
||
| /// A modal-alert body that keeps fixed explanatory copy separate from | ||
| /// user-sized details. | ||
| struct CmuxAlertContent: Equatable, Sendable { | ||
| private static let maximumFixedTextHeightFraction: CGFloat = 0.2 | ||
|
|
||
| let informativeText: String | ||
| let scrollableDetails: String? | ||
| let flattenedText: String | ||
|
|
||
| init(informativeText: String) { | ||
| self.informativeText = informativeText | ||
| scrollableDetails = nil | ||
| flattenedText = informativeText | ||
| } | ||
|
|
||
| init(flattenedText: String, separatingScrollableDetails details: String) { | ||
| self.flattenedText = flattenedText | ||
|
|
||
| guard !details.isEmpty, | ||
| let range = flattenedText.range(of: details, options: .backwards) else { | ||
| informativeText = "" | ||
| scrollableDetails = flattenedText | ||
| return | ||
| } | ||
|
|
||
| var summary = flattenedText | ||
| summary.removeSubrange(range) | ||
| while summary.contains("\n\n\n") { | ||
| summary = summary.replacingOccurrences(of: "\n\n\n", with: "\n\n") | ||
| } | ||
| informativeText = summary.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| scrollableDetails = details | ||
| } | ||
|
|
||
| static func scrollingAll(_ text: String) -> Self { | ||
| Self(flattenedText: text, separatingScrollableDetails: text) | ||
| } | ||
|
|
||
| @MainActor | ||
| func apply(to alert: NSAlert, presentingWindow: NSWindow?) { | ||
| let visibleFrame = (presentingWindow?.screen ?? alert.window.screen ?? NSScreen.main)?.visibleFrame | ||
| ?? NSRect(x: 0, y: 0, width: 1024, height: 768) | ||
| apply(to: alert, visibleFrame: visibleFrame) | ||
| } | ||
|
|
||
| @MainActor | ||
| func apply(to alert: NSAlert, visibleFrame: NSRect) { | ||
| if let scrollableDetails, !scrollableDetails.isEmpty { | ||
| let flattenedMeasurement = CmuxAlertScrollableDetailsView( | ||
| text: flattenedText, | ||
| visibleFrame: visibleFrame | ||
| ) | ||
| guard flattenedMeasurement.isContentHeightCapped else { | ||
| alert.informativeText = flattenedText | ||
| return | ||
| } | ||
|
|
||
| guard !informativeText.isEmpty else { | ||
| alert.informativeText = "" | ||
| alert.accessoryView = flattenedMeasurement | ||
| return | ||
| } | ||
|
|
||
| let summaryMeasurement = CmuxAlertScrollableDetailsView( | ||
| text: informativeText, | ||
| visibleFrame: visibleFrame | ||
| ) | ||
| if summaryMeasurement.contentHeight > visibleFrame.height * Self.maximumFixedTextHeightFraction { | ||
| alert.informativeText = "" | ||
| alert.accessoryView = flattenedMeasurement | ||
| return | ||
| } | ||
| alert.informativeText = informativeText | ||
| alert.accessoryView = CmuxAlertScrollableDetailsView( | ||
| text: scrollableDetails, | ||
| visibleFrame: visibleFrame | ||
| ) | ||
| return | ||
| } | ||
|
|
||
| let overflowView = CmuxAlertScrollableDetailsView( | ||
| text: informativeText, | ||
| visibleFrame: visibleFrame | ||
| ) | ||
| if overflowView.isContentHeightCapped { | ||
| alert.informativeText = "" | ||
| alert.accessoryView = overflowView | ||
| } else { | ||
| alert.informativeText = informativeText | ||
| } | ||
| } | ||
| } | ||
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,82 @@ | ||
| import AppKit | ||
|
|
||
| /// A read-only alert details view whose viewport is capped to the visible | ||
| /// screen while its complete text remains scrollable and selectable. | ||
| @MainActor | ||
| final class CmuxAlertScrollableDetailsView: NSScrollView { | ||
| static let accessibilityIdentifier = "CmuxAlertScrollableDetails" | ||
| static let maximumVisibleFrameHeightFraction: CGFloat = 0.4 | ||
|
|
||
| private(set) var contentHeight: CGFloat = 0 | ||
| let maximumHeight: CGFloat | ||
|
|
||
| var isContentHeightCapped: Bool { | ||
| contentHeight > frame.height | ||
| } | ||
|
|
||
| static func maximumHeight(for visibleFrame: NSRect) -> CGFloat { | ||
| max(44, floor(visibleFrame.height * maximumVisibleFrameHeightFraction)) | ||
| } | ||
|
|
||
| init(text: String, visibleFrame: NSRect) { | ||
| let width = min(420, max(260, floor(visibleFrame.width * 0.55))) | ||
| maximumHeight = Self.maximumHeight(for: visibleFrame) | ||
|
|
||
| super.init(frame: NSRect(x: 0, y: 0, width: width, height: maximumHeight)) | ||
|
|
||
| borderType = .bezelBorder | ||
| drawsBackground = true | ||
| backgroundColor = .textBackgroundColor | ||
| hasHorizontalScroller = false | ||
| hasVerticalScroller = true | ||
| autohidesScrollers = true | ||
| setAccessibilityIdentifier(Self.accessibilityIdentifier) | ||
|
|
||
| let textView = NSTextView(frame: NSRect(x: 0, y: 0, width: contentSize.width, height: 1)) | ||
| textView.string = text | ||
| textView.isEditable = false | ||
| textView.isSelectable = true | ||
| textView.drawsBackground = false | ||
| textView.font = .systemFont(ofSize: NSFont.systemFontSize) | ||
| textView.textColor = .labelColor | ||
| textView.textContainerInset = NSSize(width: 6, height: 6) | ||
| textView.isHorizontallyResizable = false | ||
| textView.isVerticallyResizable = true | ||
| textView.autoresizingMask = [.width] | ||
| textView.minSize = NSSize(width: 0, height: 0) | ||
| textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) | ||
| textView.textContainer?.lineBreakMode = .byCharWrapping | ||
| textView.textContainer?.lineFragmentPadding = 0 | ||
| textView.textContainer?.widthTracksTextView = true | ||
| textView.textContainer?.containerSize = NSSize( | ||
| width: contentSize.width, | ||
| height: CGFloat.greatestFiniteMagnitude | ||
| ) | ||
|
|
||
| if let layoutManager = textView.layoutManager, | ||
| let textContainer = textView.textContainer { | ||
| layoutManager.ensureLayout(for: textContainer) | ||
| textView.sizeToFit() | ||
| layoutManager.ensureLayout(for: textContainer) | ||
| contentHeight = ceil( | ||
| layoutManager.usedRect(for: textContainer).height | ||
| + textView.textContainerInset.height * 2 | ||
| ) | ||
| } | ||
|
|
||
| let viewportHeight = min(max(44, contentHeight), maximumHeight) | ||
| setFrameSize(NSSize(width: width, height: viewportHeight)) | ||
| textView.setFrameSize(NSSize(width: contentSize.width, height: max(contentHeight, viewportHeight))) | ||
| hasVerticalScroller = contentHeight > viewportHeight | ||
| documentView = textView | ||
| } | ||
|
|
||
| @available(*, unavailable) | ||
| required init?(coder: NSCoder) { | ||
| fatalError("init(coder:) has not been implemented") | ||
| } | ||
|
|
||
| override var intrinsicContentSize: NSSize { | ||
| frame.size | ||
| } | ||
| } |
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
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.