Skip to content

Commit f128cb0

Browse files
Chris Fieldsclaude
andcommitted
Prefer most specific workstream match for directory lookups
When multiple workstreams could match a window's directory, prefer the one with the longest (most specific) path. This prevents a workstream set to ~/Projects from "stealing" windows that should match a more specific workstream like ~/Projects/specific-project. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f2ed33a commit f128cb0

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

ThemeManager.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,19 +402,24 @@ class ThemeManager: ObservableObject {
402402

403403
/// Find a workstream that matches the given directory path.
404404
/// Used to identify windows not launched by the app (e.g., opened manually).
405+
/// Prefers the most specific (longest path) match when multiple workstreams could match.
405406
func workstreamForDirectory(_ directory: String) -> Workstream? {
406-
// Exact match first
407-
if let ws = workstreams.first(where: { $0.directory == directory }) {
408-
return ws
409-
}
410-
// Check if directory is a subdirectory of a workstream's directory
407+
var bestMatch: Workstream? = nil
408+
var bestMatchLength = 0
409+
411410
for ws in workstreams {
412411
guard let wsDir = ws.directory, !wsDir.isEmpty else { continue }
413-
if directory.hasPrefix(wsDir + "/") {
414-
return ws
412+
413+
// Check exact match or subdirectory match
414+
if directory == wsDir || directory.hasPrefix(wsDir + "/") {
415+
// Prefer longer (more specific) paths
416+
if wsDir.count > bestMatchLength {
417+
bestMatch = ws
418+
bestMatchLength = wsDir.count
419+
}
415420
}
416421
}
417-
return nil
422+
return bestMatch
418423
}
419424

420425
/// Get workstream name for a Ghostty PID.

0 commit comments

Comments
 (0)