Repository navigation
Move tabs into new workspaces #3285
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
Changes from 1 commit
0c35782
55c0472
acb898c
aabf442
24e7fa5
c43dae8
0b8b8b8
f1118b6
fb5f3f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import Foundation | ||
|
|
||
| extension CMUXCLI { | ||
| func applyTabActionFocusOption(_ focusOpt: String?, to params: inout [String: Any]) throws { | ||
| guard let focusOpt else { return } | ||
| guard let focus = parseBoolString(focusOpt) else { | ||
| throw CLIError(message: "--focus must be true|false") | ||
| } | ||
| params["focus"] = focus | ||
| } | ||
|
|
||
| func appendCreatedWorkspaceSummaryParts( | ||
| from payload: [String: Any], | ||
| idFormat: CLIIDFormat, | ||
| to summaryParts: inout [String] | ||
| ) { | ||
| guard let id = payload["created_workspace_id"] as? String else { return } | ||
| var createdWorkspacePayload: [String: Any] = ["workspace_id": id] | ||
| if let ref = payload["created_workspace_ref"] as? String { | ||
| createdWorkspacePayload["workspace_ref"] = ref | ||
| } | ||
| if let createdWorkspace = formatHandle(createdWorkspacePayload, kind: "workspace", idFormat: idFormat) { | ||
| summaryParts.append("created_workspace=\(createdWorkspace)") | ||
| } | ||
| } | ||
|
|
||
| func runMoveTabToNewWorkspace( | ||
| commandArgs: [String], | ||
| client: SocketClient, | ||
| jsonOutput: Bool, | ||
| idFormat: CLIIDFormat, | ||
| windowOverride: String? | ||
| ) throws { | ||
| if commandArgs.contains(where: { $0 == "--action" || $0.hasPrefix("--action=") }) { | ||
| throw CLIError(message: "move-tab-to-new-workspace does not accept --action") | ||
| } | ||
| try runTabAction( | ||
| commandArgs: ["--action", "move-to-new-workspace"] + commandArgs, | ||
| client: client, | ||
| jsonOutput: jsonOutput, | ||
| idFormat: idFormat, | ||
| windowOverride: windowOverride | ||
| ) | ||
| } | ||
|
|
||
| static let moveTabToNewWorkspaceCommandHelp = """ | ||
| Usage: cmux move-tab-to-new-workspace [--tab <id|ref>] [--surface <id|ref>] [--workspace <id|ref>] [--title <text>] [--focus <true|false>] | ||
|
|
||
| Move a tab into a newly created workspace in the same window. | ||
|
|
||
| Flags: | ||
| --tab <id|ref|index> Target tab (accepts tab:<n> or surface:<n>; default: $CMUX_TAB_ID, then $CMUX_SURFACE_ID, then focused tab) | ||
| --surface <id|ref|index> Alias for --tab | ||
| --workspace <id|ref|index> Workspace context (default: current/$CMUX_WORKSPACE_ID) | ||
| --title <text> Optional title for the new workspace | ||
| --focus <true|false> Focus the new workspace when supported | ||
|
|
||
| Example: | ||
| cmux move-tab-to-new-workspace --tab tab:2 | ||
| cmux move-tab-to-new-workspace --surface surface:3 --title "build logs" | ||
| """ | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2626,10 +2626,10 @@ struct CMUXCLI { | |||||||||||||
|
|
||||||||||||||
| case "workspace-action": | ||||||||||||||
| try runWorkspaceAction(commandArgs: commandArgs, client: client, jsonOutput: jsonOutput, idFormat: idFormat, windowOverride: windowId) | ||||||||||||||
|
|
||||||||||||||
| case "tab-action": | ||||||||||||||
| try runTabAction(commandArgs: commandArgs, client: client, jsonOutput: jsonOutput, idFormat: idFormat, windowOverride: windowId) | ||||||||||||||
|
|
||||||||||||||
| case "move-tab-to-new-workspace", "detach-tab": | ||||||||||||||
| try runMoveTabToNewWorkspace(commandArgs: commandArgs, client: client, jsonOutput: jsonOutput, idFormat: idFormat, windowOverride: windowId) | ||||||||||||||
| case "rename-tab": | ||||||||||||||
| try runRenameTab(commandArgs: commandArgs, client: client, jsonOutput: jsonOutput, idFormat: idFormat, windowOverride: windowId) | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -3935,7 +3935,7 @@ struct CMUXCLI { | |||||||||||||
| return nil | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| private func parseBoolString(_ raw: String) -> Bool? { | ||||||||||||||
| func parseBoolString(_ raw: String) -> Bool? { | ||||||||||||||
| switch raw.lowercased() { | ||||||||||||||
| case "1", "true", "yes", "on": | ||||||||||||||
| return true | ||||||||||||||
|
|
@@ -4134,7 +4134,7 @@ struct CMUXCLI { | |||||||||||||
| return "tab:\(ordinal)" | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| private func formatHandle(_ payload: [String: Any], kind: String, idFormat: CLIIDFormat) -> String? { | ||||||||||||||
| func formatHandle(_ payload: [String: Any], kind: String, idFormat: CLIIDFormat) -> String? { | ||||||||||||||
| let id = payload["\(kind)_id"] as? String | ||||||||||||||
| let ref = payload["\(kind)_ref"] as? String | ||||||||||||||
| switch idFormat { | ||||||||||||||
|
|
@@ -4564,7 +4564,7 @@ struct CMUXCLI { | |||||||||||||
| printV2Payload(payload, jsonOutput: jsonOutput, idFormat: idFormat, fallbackText: summaryParts.joined(separator: " ")) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| private func runTabAction( | ||||||||||||||
| func runTabAction( | ||||||||||||||
| commandArgs: [String], | ||||||||||||||
| client: SocketClient, | ||||||||||||||
| jsonOutput: Bool, | ||||||||||||||
|
|
@@ -4577,8 +4577,9 @@ struct CMUXCLI { | |||||||||||||
| let (actionOpt, rem3) = parseOption(rem2, name: "--action") | ||||||||||||||
| let (titleOpt, rem4) = parseOption(rem3, name: "--title") | ||||||||||||||
| let (urlOpt, rem5) = parseOption(rem4, name: "--url") | ||||||||||||||
| let (focusOpt, rem6) = parseOption(rem5, name: "--focus") | ||||||||||||||
|
|
||||||||||||||
| var positional = rem5 | ||||||||||||||
| var positional = rem6 | ||||||||||||||
| let actionRaw: String | ||||||||||||||
| if let actionOpt { | ||||||||||||||
| actionRaw = actionOpt | ||||||||||||||
|
|
@@ -4632,24 +4633,16 @@ struct CMUXCLI { | |||||||||||||
| if let urlOpt, !urlOpt.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { | ||||||||||||||
| params["url"] = urlOpt.trimmingCharacters(in: .whitespacesAndNewlines) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| try applyTabActionFocusOption(focusOpt, to: ¶ms) | ||||||||||||||
|
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. Set a non-focus default when Line 4636 only applies Suggested fix- try applyTabActionFocusOption(focusOpt, to: ¶ms)
+ if action == "move-to-new-workspace", focusOpt == nil {
+ params["focus"] = false
+ } else {
+ try applyTabActionFocusOption(focusOpt, to: ¶ms)
+ }Based on learnings: "Socket/CLI commands must not steal macOS app focus ... only explicit focus-intent commands may mutate in-app focus/selection ... all non-focus commands should preserve current user focus context." 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| let payload = try client.sendV2(method: "tab.action", params: params) | ||||||||||||||
| var summaryParts = ["OK", "action=\(action)"] | ||||||||||||||
| if let tabHandle = formatTabHandle(payload, idFormat: idFormat) { | ||||||||||||||
| summaryParts.append("tab=\(tabHandle)") | ||||||||||||||
| } | ||||||||||||||
| if let workspaceHandle = formatHandle(payload, kind: "workspace", idFormat: idFormat) { | ||||||||||||||
| summaryParts.append("workspace=\(workspaceHandle)") | ||||||||||||||
| } | ||||||||||||||
| if let closed = payload["closed"] { | ||||||||||||||
| summaryParts.append("closed=\(closed)") | ||||||||||||||
| } | ||||||||||||||
| if let created = formatCreatedTabHandle(payload, idFormat: idFormat) { | ||||||||||||||
| summaryParts.append("created=\(created)") | ||||||||||||||
| } | ||||||||||||||
| if let tabHandle = formatTabHandle(payload, idFormat: idFormat) { summaryParts.append("tab=\(tabHandle)") } | ||||||||||||||
| if let workspaceHandle = formatHandle(payload, kind: "workspace", idFormat: idFormat) { summaryParts.append("workspace=\(workspaceHandle)") } | ||||||||||||||
| if let closed = payload["closed"] { summaryParts.append("closed=\(closed)") } | ||||||||||||||
| if let created = formatCreatedTabHandle(payload, idFormat: idFormat) { summaryParts.append("created=\(created)") } | ||||||||||||||
| appendCreatedWorkspaceSummaryParts(from: payload, idFormat: idFormat, to: &summaryParts) | ||||||||||||||
| printV2Payload(payload, jsonOutput: jsonOutput, idFormat: idFormat, fallbackText: summaryParts.joined(separator: " ")) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| private func runRenameTab( | ||||||||||||||
| commandArgs: [String], | ||||||||||||||
| client: SocketClient, | ||||||||||||||
|
|
@@ -8844,6 +8837,7 @@ struct CMUXCLI { | |||||||||||||
| rename | clear-name | ||||||||||||||
| close-left | close-right | close-others | ||||||||||||||
| new-terminal-right | new-browser-right | ||||||||||||||
| move-to-new-workspace | ||||||||||||||
| reload | duplicate | ||||||||||||||
| pin | unpin | ||||||||||||||
| mark-unread | ||||||||||||||
|
|
@@ -8855,12 +8849,16 @@ struct CMUXCLI { | |||||||||||||
| --workspace <id|ref|index> Workspace context (default: current/$CMUX_WORKSPACE_ID) | ||||||||||||||
| --title <text> Title for rename (or pass trailing title text) | ||||||||||||||
| --url <url> Optional URL for new-browser-right | ||||||||||||||
| --focus <true|false> Focus the destination when supported | ||||||||||||||
|
|
||||||||||||||
| Example: | ||||||||||||||
| cmux tab-action --tab tab:3 --action pin | ||||||||||||||
| cmux tab-action --action close-right | ||||||||||||||
| cmux tab-action --tab tab:2 --action move-to-new-workspace | ||||||||||||||
| cmux tab-action --tab tab:2 --action rename --title "build logs" | ||||||||||||||
| """ | ||||||||||||||
| case "move-tab-to-new-workspace", "detach-tab": | ||||||||||||||
| return Self.moveTabToNewWorkspaceCommandHelp | ||||||||||||||
| case "rename-tab": | ||||||||||||||
| return """ | ||||||||||||||
| Usage: cmux rename-tab [--workspace <id|ref>] [--tab <id|ref>] [--surface <id|ref>] [--] <title> | ||||||||||||||
|
|
@@ -17996,6 +17994,7 @@ export default CMUXSessionRestore; | |||||||||||||
| move-workspace-to-window --workspace <id|ref> --window <id|ref> | ||||||||||||||
| reorder-workspace --workspace <id|ref|index> (--index <n> | --before <id|ref|index> | --after <id|ref|index>) [--window <id|ref|index>] | ||||||||||||||
| workspace-action --action <name> [--workspace <id|ref|index>] [--title <text>] [--color <name|#hex>] [--description <text>] | ||||||||||||||
| move-tab-to-new-workspace [--tab <id|ref|index>] [--surface <id|ref|index>] [--workspace <id|ref|index>] [--title <text>] [--focus <true|false>] | ||||||||||||||
| list-workspaces | ||||||||||||||
| new-workspace [--name <title>] [--description <text>] [--cwd <path>] [--command <text>] [--layout <json>] | ||||||||||||||
| ssh <destination> [--name <title>] [--port <n>] [--identity <path>] [--ssh-option <opt>] [--no-focus] [-- <remote-command-args>] | ||||||||||||||
|
|
@@ -18010,7 +18009,7 @@ export default CMUXSessionRestore; | |||||||||||||
| close-surface [--surface <id|ref>] [--workspace <id|ref>] | ||||||||||||||
| move-surface --surface <id|ref|index> [--pane <id|ref|index>] [--workspace <id|ref|index>] [--window <id|ref|index>] [--before <id|ref|index>] [--after <id|ref|index>] [--index <n>] [--focus <true|false>] | ||||||||||||||
| reorder-surface --surface <id|ref|index> (--index <n> | --before <id|ref|index> | --after <id|ref|index>) | ||||||||||||||
| tab-action --action <name> [--tab <id|ref|index>] [--surface <id|ref|index>] [--workspace <id|ref|index>] [--title <text>] [--url <url>] | ||||||||||||||
| tab-action --action <name> [--tab <id|ref|index>] [--surface <id|ref|index>] [--workspace <id|ref|index>] [--title <text>] [--url <url>] [--focus <true|false>] | ||||||||||||||
| rename-tab [--workspace <id|ref>] [--tab <id|ref>] [--surface <id|ref>] <title> | ||||||||||||||
| drag-surface-to-split --surface <id|ref> <left|right|up|down> | ||||||||||||||
| refresh-surfaces | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.