Skip to content

Sort alphabetically - Folders on top #2028

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 2 commits into from
Apr 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ struct ProjectNavigatorOutlineView: NSViewControllerRepresentable {
.store(in: &cancellables)
workspace.$navigatorFilter
.throttle(for: 0.1, scheduler: RunLoop.main, latest: true)
.sink { [weak self] _ in self?.controller?.handleFilterChange() }
.sink { [weak self] _ in
self?.controller?.handleFilterChange()
}
.store(in: &cancellables)
workspace.$sourceControlFilter
Publishers.Merge(workspace.$sourceControlFilter, workspace.$sortFoldersOnTop)
.throttle(for: 0.1, scheduler: RunLoop.main, latest: true)
.sink { [weak self] _ in self?.controller?.handleFilterChange() }
.sink { [weak self] _ in
self?.controller?.handleFilterChange()
}
.store(in: &cancellables)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,29 @@ extension ProjectNavigatorViewController: NSOutlineViewDataSource {
private func getOutlineViewItems(for item: CEWorkspaceFile) -> [CEWorkspaceFile] {
if let cachedChildren = filteredContentChildren[item] {
return cachedChildren
.sorted { lhs, rhs in
workspace?.sortFoldersOnTop == true ? lhs.isFolder && !rhs.isFolder : lhs.name < rhs.name
}
}

if let children = workspace?.workspaceFileManager?.childrenOfFile(item) {
if let filter = workspace?.navigatorFilter, let sourceControlFilter = workspace?.sourceControlFilter,
!filter.isEmpty || sourceControlFilter {
if let workspace, let children = workspace.workspaceFileManager?.childrenOfFile(item) {
if !workspace.navigatorFilter.isEmpty || workspace.sourceControlFilter {
let filteredChildren = children.filter {
fileSearchMatches(filter, for: $0, sourceControlFilter: sourceControlFilter)
fileSearchMatches(
workspace.navigatorFilter,
for: $0,
sourceControlFilter: workspace.sourceControlFilter
)
}

filteredContentChildren[item] = filteredChildren
return filteredChildren
}

return children
.sorted { lhs, rhs in
workspace.sortFoldersOnTop ? lhs.isFolder && !rhs.isFolder : lhs.name < rhs.name
}
}

return []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@ struct ProjectNavigatorToolbarBottom: View {
text: $workspace.navigatorFilter,
leadingAccessories: {
FilterDropDownIconButton(menu: {
Button {
workspace.sortFoldersOnTop.toggle()
} label: {
Text(workspace.sortFoldersOnTop ? "Alphabetically" : "Folders on top")
ForEach([(true, "Folders on top"), (false, "Alphabetically")], id: \.0) { value, title in
Button {
// Avoid calling the handleFilterChange method
if workspace.sortFoldersOnTop != value {
workspace.sortFoldersOnTop = value
}
} label: {
HStack {
if value == workspace.sortFoldersOnTop {
Image(systemName: "checkmark")
}
Text(title)
}
}
}
}, isOn: !workspace.navigatorFilter.isEmpty)
.padding(.leading, 4)
Expand Down