Skip to content

Sort the stacked-window list alphabetically - #1909

Merged
rxhanson merged 2 commits into
rxhanson:mainfrom
MyronKoch:feat/stack-list-alphabetical
Oct 14, 2026
Merged

rxhanson merged 2 commits into
rxhanson:mainfrom
MyronKoch:feat/stack-list-alphabetical

Conversation

@MyronKoch

@MyronKoch MyronKoch commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

The stacked-window list currently shows windows front to back, so its order changes every time a window is raised: the window you just picked jumps to the top next hover, and everything else shifts down a row. With two or three windows that is fine. With a long stack (I regularly have 15+ terminals at one corner) it means re-reading the whole list every time, because nothing stays where it was.

This sorts the list by title instead, so each window keeps its row:

  • localizedStandardCompare (the Finder's ordering): case-insensitive, and Terminal 2 comes before Terminal 10.
  • Window id breaks ties, so windows with identical titles also keep a stable order.
  • The cycle shortcuts from Add shortcuts to cycle through stacked windows #1883 are untouched and still go front to back. The list and the cycle never shared an order source.

Running it as my daily driver with a 17-window stack. Full suite: 524 passed, 0 failed.

Happy to make this a setting instead if you would rather keep front-to-back as the default.

The list showed windows front to back, so every raise reshuffled it and a
window never kept its row from one hover to the next. With a long stack
that makes the list slow to scan. Sort by title instead (Finder-style:
case-insensitive, numbers in natural order), with window id as the
tiebreak so identical titles keep a stable order too.

The cycle shortcuts keep their own front-to-back order; only the list
changes.
@MyronKoch
MyronKoch marked this pull request as draft October 12, 2026 05:31
}

return windows.map { info in
return listOrder(windows.map { info in

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Swift, I'm used to seeing sorting done by calling .sorted on the mapped collection, something like this:

return windows.map { info in
    StackBadgeStackedWindow(
        windowId: info.id,
        pid: info.pid,
        title: displayTitle(for: info, axTitle: titles[info.id])
    )
}.sorted { lhs, rhs in
    let comparison = lhs.title.localizedStandardCompare(rhs.title)
    if comparison != .orderedSame {
        return comparison == .orderedAscending
    }
    return lhs.windowId < rhs.windowId
}

Of course, if this were reused elsewhere then something reusable like this function would be preferred.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, inlined it as you suggested. The helper was only there so unit tests could reach the sort without accessibility, so I dropped those along with it.

Chain .sorted onto the map per review; the helper existed only so unit tests could reach the sort, so those go with it.
@MyronKoch
MyronKoch marked this pull request as ready for review October 12, 2026 22:58
@rxhanson
rxhanson merged commit 8a2be8b into rxhanson:main Oct 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants