Repository navigation
Lawrence Sidebar: coalesce rapid selections + Equatable subtree boundary #8316
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ed01945
Coalesce rapid sidebar clicks to the latest selection (Lawrence Sidebar)
6be5900
Equatable boundary on VerticalTabsSidebar (Lawrence Sidebar)
489ae5c
Enforce hover state authoritatively on visible sidebar cells (Lawrenc…
4d0cbed
Review fixes: hover sweep re-applies full model; coalescer uses injec…
729977c
Merge remote-tracking branch 'origin/main' into feat-lawrence-selecti…
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
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
56 changes: 56 additions & 0 deletions
56
Sources/Sidebar/AppKitList/SidebarSelectionCoalescer.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,56 @@ | ||
| import AppKit | ||
| import QuartzCore | ||
|
|
||
| /// Coalesces rapid plain-click workspace selections to the latest request. | ||
| /// | ||
| /// A selection commit re-renders the container and swaps the terminal | ||
| /// content (~tens of ms); without coalescing, a burst of clicks queues one | ||
| /// full commit per click and later selections feel progressively slower. | ||
| /// Leading edge applies immediately (single clicks keep their latency); | ||
| /// clicks landing inside the window replace the pending request and one | ||
| /// trailing fire applies only the newest. The row's optimistic press | ||
| /// highlight still tracks every click instantly. | ||
| @MainActor | ||
| final class SidebarSelectionCoalescer { | ||
| private var pendingApply: (() -> Void)? | ||
| private var trailingTask: Task<Void, Never>? | ||
| private var lastApplied: CFTimeInterval = 0 | ||
| private let window: TimeInterval | ||
| private let clock: any Clock<Duration> | ||
|
|
||
| init(window: TimeInterval = 0.1, clock: any Clock<Duration> = ContinuousClock()) { | ||
| self.window = window | ||
| self.clock = clock | ||
| } | ||
|
|
||
| func request(_ apply: @escaping @MainActor () -> Void) { | ||
| let now = CACurrentMediaTime() | ||
| if trailingTask == nil, now - lastApplied >= window { | ||
| lastApplied = now | ||
| apply() | ||
| return | ||
| } | ||
| pendingApply = apply | ||
| guard trailingTask == nil else { return } | ||
| let delay = max(0, window - (now - lastApplied)) | ||
| // Injected-Clock sleep with cancellation wired to `cancel()`, per the | ||
| // bounded-delay policy (no raw Task.sleep in production paths). | ||
| trailingTask = Task { [weak self, clock] in | ||
| try? await clock.sleep(for: .seconds(delay)) | ||
| guard let self, !Task.isCancelled else { return } | ||
| self.trailingTask = nil | ||
| self.lastApplied = CACurrentMediaTime() | ||
| let apply = self.pendingApply | ||
| self.pendingApply = nil | ||
| apply?() | ||
| } | ||
| } | ||
|
|
||
| /// Drops any pending request. Used before selection paths that must not | ||
| /// be reordered (modifier clicks mutate the multi-selection set). | ||
| func cancel() { | ||
| trailingTask?.cancel() | ||
| trailingTask = nil | ||
| pendingApply = nil | ||
| } | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
cmux-swift-architectural-rethinkrule flags timing repair paths used to paper over rendering races. The coalescer reduces how oftenupdateSelectiontriggers a container re-render and terminal-content swap, but does not name or fix why a singleupdateSelectioncall is expensive enough to cause noticeable serial slowdown. A rapid burst on a slower machine, or a future caller outside the flag, will surface the same problem. Consider documenting what the expensive operation is and whether it can be made idempotent (skipping work when the workspace being selected is already selected) or deferred to the next run-loop turn.