Repository navigation
Sync settings sidebar and open notifications at turn start #5528
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
duroey
wants to merge
10
commits into
manaflow-ai:main
Choose a base branch
from
duroey:codex/notification-turn-anchor
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 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2973e3f
test: cover notification turn-start anchors
duroey 4787b51
fix: reopen notifications at prompt start
duroey 2de6880
fix: address notification anchor review feedback
duroey aa76e99
fix: address notification anchor review followups
duroey 48bae5b
fix: clear notification anchor aliases
duroey e3f5d03
fix(settings): sync sidebar selection while scrolling
duroey c574b5f
test(notifications): cover turn-start notification anchors
duroey cb3dc5f
fix(notifications): open terminal notifications at turn start
duroey cdf51a4
fix: address notification anchor review feedback
duroey d7a35a5
fix(settings): replace visibility namespace enum
duroey 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
123 changes: 123 additions & 0 deletions
123
...ges/CmuxSettingsUI/Sources/CmuxSettingsUI/Navigation/SettingsVisibleSectionResolver.swift
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,123 @@ | ||
| import CoreGraphics | ||
| import SwiftUI | ||
|
|
||
| enum SettingsSectionVisibilityCoordinateSpace { | ||
| static let name = "SettingsSectionVisibilityCoordinateSpace" | ||
| } | ||
|
|
||
| struct SettingsSectionFramePreferenceKey: PreferenceKey { | ||
| static let defaultValue: [SettingsSectionID: CGRect] = [:] | ||
|
|
||
| /// Merges section frames reported by every visibility marker. | ||
| /// | ||
| /// - Parameters: | ||
| /// - value: Current aggregate section frame map. | ||
| /// - nextValue: Next lazily produced section frame map from SwiftUI. | ||
| static func reduce( | ||
| value: inout [SettingsSectionID: CGRect], | ||
| nextValue: () -> [SettingsSectionID: CGRect] | ||
| ) { | ||
| value.merge(nextValue()) { _, newValue in newValue } | ||
| } | ||
| } | ||
|
|
||
| struct SettingsSectionVisibilityMarker: View { | ||
| let section: SettingsSectionID | ||
|
|
||
| var body: some View { | ||
| GeometryReader { proxy in | ||
| Color.clear.preference( | ||
| key: SettingsSectionFramePreferenceKey.self, | ||
| value: [section: proxy.frame(in: .named(SettingsSectionVisibilityCoordinateSpace.name))] | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension View { | ||
| /// Reports this view's frame as the scroll-position marker for a settings section. | ||
| /// | ||
| /// - Parameter section: Section represented by the view. | ||
| /// - Returns: A view that publishes its frame through `SettingsSectionFramePreferenceKey`. | ||
| func settingsSectionVisibility(_ section: SettingsSectionID) -> some View { | ||
| background(SettingsSectionVisibilityMarker(section: section)) | ||
| } | ||
| } | ||
|
|
||
| struct SettingsVisibleSectionResolver: Sendable { | ||
| struct Configuration: Sendable { | ||
| static let defaultActivationY: CGFloat = 0 | ||
|
|
||
| let activationY: CGFloat | ||
|
|
||
| /// Creates a resolver configuration. | ||
| /// | ||
| /// - Parameter activationY: Vertical viewport coordinate that decides when | ||
| /// a section becomes active. A section is active after its top edge | ||
| /// crosses this coordinate. | ||
| init(activationY: CGFloat = Self.defaultActivationY) { | ||
| self.activationY = activationY | ||
| } | ||
| } | ||
|
|
||
| /// Resolves the section that should be selected for the current scroll position. | ||
| /// | ||
| /// - Parameters: | ||
| /// - frames: Current section frames in the settings detail scroll coordinate space. | ||
| /// - orderedSections: Sections in visual scroll order. | ||
| /// - configuration: Resolver options, including the activation line. | ||
| /// - Returns: The active section, or `nil` when no tracked frames are available. | ||
| static func visibleSection( | ||
| in frames: [SettingsSectionID: CGRect], | ||
| orderedSections: [SettingsSectionID] = SettingsSectionID.allCases, | ||
| configuration: Configuration = Configuration() | ||
| ) -> SettingsSectionID? { | ||
| let orderedFrames = orderedSections.enumerated().compactMap { index, section -> SectionFrame? in | ||
| guard let frame = frames[section] else { return nil } | ||
| return SectionFrame(index: index, section: section, frame: frame) | ||
| } | ||
|
|
||
| guard !orderedFrames.isEmpty else { return nil } | ||
|
|
||
| let containingFrames = orderedFrames.filter { | ||
| $0.frame.minY <= configuration.activationY && $0.frame.maxY >= configuration.activationY | ||
| } | ||
| if let active = nearestFrameToActivationLine(in: containingFrames) { | ||
| return active.section | ||
| } | ||
|
|
||
| let crossedFrames = orderedFrames.filter { $0.frame.minY <= configuration.activationY } | ||
| if let active = nearestFrameToActivationLine(in: crossedFrames) { | ||
| return active.section | ||
| } | ||
|
|
||
| return orderedFrames.min(by: { lhs, rhs in | ||
| if lhs.frame.minY == rhs.frame.minY { | ||
| return lhs.index < rhs.index | ||
| } | ||
| return lhs.frame.minY < rhs.frame.minY | ||
| })?.section | ||
| } | ||
|
|
||
| /// Selects the frame whose top edge is closest to the activation line. | ||
| /// | ||
| /// - Parameter frames: Section frames already filtered to eligible candidates. | ||
| /// - Returns: The nearest eligible frame, or `nil` when no candidates exist. | ||
| private static func nearestFrameToActivationLine(in frames: [SectionFrame]) -> SectionFrame? { | ||
| if let active = frames.max(by: { lhs, rhs in | ||
| if lhs.frame.minY == rhs.frame.minY { | ||
| return lhs.index < rhs.index | ||
| } | ||
| return lhs.frame.minY < rhs.frame.minY | ||
| }) { | ||
| return active | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| private struct SectionFrame { | ||
| let index: Int | ||
| let section: SettingsSectionID | ||
| let frame: CGRect | ||
| } | ||
| } | ||
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
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.