src/switcher/state/WindowOrderResolverSpecs.md
Line coverage:
WindowOrderResolver.swift96% · refreshed 2026-05-27 by/coverage-explore
WindowOrderResolver.isOrderedBefore decides the order windows appear in the switcher. It's the
comparator behind Windows.sort, extracted as a pure kernel: the caller precomputes each window's
ordering facts once (OrderWindow — a window's WindowState + its ApplicationState + the
query-derived search rank) and the kernel compares two of them; the sort-mode knobs (searchActive,
windowlessAtEnd, hiddenAtEnd, minimizedAtEnd, sortType) are labeled parameters with defaults,
hoisted once per sort by the caller and captured by the comparator closure. Besides testability,
precomputing OrderWindows let the sort drop from O(n log n) Search calls to O(n) (facts are
snapshotted once).
Decision order:
lastFocusOrder.recentlyFocused (lowest lastFocusOrder), recentlyCreated (highest
creationOrder), alphabetical (app name, then title; localizedStandardCompare), or space
(all-spaces windows first, then lowest space index, then alphabetical).lastFocusOrder (for the alphabetical/space paths).recentlyFocused/recentlyCreated return directly (no alphabetical tiebreak); the lastFocusOrder
tiebreak applies to the alphabetical/space paths.space: windows on all spaces sort ahead of space-bound ones; ties within a space fall back to
alphabetical, then lastFocusOrder.Array.sort).Mirrors WindowOrderResolverTests.swift 1:1.
lastFocusOrder.lastFocusOrder first.creationOrder first.lastFocusOrder.testSpaceAllSpacesWindowsFirst: only b on all spaces → b sorts first (pins comparator symmetry).