Repository navigation
Follow up equalize splits shortcut fixes #3309
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 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e2f4d36
Expose equalize splits as a cmux shortcut
c8a583e
Make equalize splits shortcut merge-ready
austinywang f5fa041
Merge origin/main and fix budget: extract didProgrammaticallyChangeSp…
austinywang a3689b8
Allow extracted equalize split support to refresh workspace layout sn…
austinywang 2498d07
Make tagged reload app names filesystem-safe
austinywang 82221b4
Avoid recursive shortcut store initialization during config parsing
austinywang 9a6b80b
Keep equalize split geometry state coherent
austinywang 0aaf57a
Respect shortcut parsing file length budget
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,7 @@ | ||
| extension AppDelegate { | ||
| func performEqualizeSplitsShortcut() { | ||
| if let workspace = tabManager?.selectedWorkspace { | ||
| _ = tabManager?.equalizeSplits(tabId: workspace.id) | ||
| } | ||
| } | ||
| } |
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
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,81 @@ | ||
| import Bonsplit | ||
| import CoreGraphics | ||
| import Foundation | ||
|
|
||
| extension TabManager { | ||
| /// Equalize splits - not directly supported by bonsplit. | ||
| func equalizeSplits(tabId: UUID) -> Bool { | ||
| guard let tab = tabs.first(where: { $0.id == tabId }) else { return false } | ||
|
|
||
| let didEqualize = equalizeSplitsOnce(in: tab) | ||
| if didEqualize { | ||
| tab.didProgrammaticallyChangeSplitGeometry() | ||
| scheduleEqualizeSplitsFollowUp(tabId: tabId) | ||
| } | ||
| return didEqualize | ||
|
austinywang marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| @discardableResult | ||
| private func equalizeSplitsOnce(in tab: Workspace) -> Bool { | ||
| var foundSplit = false | ||
| var allSucceeded = true | ||
| equalizeSplits( | ||
| in: tab.bonsplitController.treeSnapshot(), | ||
| controller: tab.bonsplitController, | ||
| foundSplit: &foundSplit, | ||
| allSucceeded: &allSucceeded | ||
| ) | ||
| return foundSplit && allSucceeded | ||
| } | ||
|
|
||
| private func scheduleEqualizeSplitsFollowUp(tabId: UUID) { | ||
| DispatchQueue.main.async { [weak self] in | ||
| self?.runEqualizeSplitsFollowUp(tabId: tabId) | ||
| } | ||
| DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) { [weak self] in | ||
| self?.runEqualizeSplitsFollowUp(tabId: tabId) | ||
| } | ||
| } | ||
|
|
||
| private func runEqualizeSplitsFollowUp(tabId: UUID) { | ||
| guard let tab = tabs.first(where: { $0.id == tabId }) else { return } | ||
| if equalizeSplitsOnce(in: tab) { | ||
| tab.didProgrammaticallyChangeSplitGeometry() | ||
| } | ||
| } | ||
|
|
||
| private func equalizeSplits( | ||
| in node: ExternalTreeNode, | ||
| controller: BonsplitController, | ||
| foundSplit: inout Bool, | ||
| allSucceeded: inout Bool | ||
| ) { | ||
| switch node { | ||
| case .pane: | ||
| return | ||
| case .split(let splitNode): | ||
| foundSplit = true | ||
| guard let splitId = UUID(uuidString: splitNode.id) else { | ||
| allSucceeded = false | ||
| return | ||
| } | ||
|
|
||
| if !controller.setDividerPosition(0.5, forSplit: splitId) { | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| allSucceeded = false | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| equalizeSplits( | ||
| in: splitNode.first, | ||
| controller: controller, | ||
| foundSplit: &foundSplit, | ||
| allSucceeded: &allSucceeded | ||
| ) | ||
| equalizeSplits( | ||
| in: splitNode.second, | ||
| controller: controller, | ||
| foundSplit: &foundSplit, | ||
| allSucceeded: &allSucceeded | ||
| ) | ||
| } | ||
| } | ||
| } | ||
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,6 @@ | ||
| extension Workspace { | ||
| func didProgrammaticallyChangeSplitGeometry() { | ||
| tmuxLayoutSnapshot = bonsplitController.layoutSnapshot() | ||
| scheduleTerminalGeometryReconcile() | ||
| } | ||
| } |
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,11 @@ | ||
| import SwiftUI | ||
|
|
||
| extension cmuxApp { | ||
| func equalizeSplitsCommandButton() -> some View { | ||
| splitCommandButton(title: String(localized: "command.equalizeSplits.title", defaultValue: "Equalize Splits"), shortcut: menuShortcut(for: .equalizeSplits)) { | ||
| if let workspace = activeTabManager.selectedWorkspace { | ||
| _ = activeTabManager.equalizeSplits(tabId: workspace.id) | ||
| } | ||
| } | ||
| } | ||
| } |
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.