Skip to content

Commit 14d9709

Browse files
LeonardoLarranagaFastestMolasses
authored andcommitted
Sort alphabetically - Folders on top (#2028)
* Sort alphabetically - Folders on top * Changed `Button` to `Toggle`
1 parent f2337c8 commit 14d9709

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorOutlineView.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ struct ProjectNavigatorOutlineView: NSViewControllerRepresentable {
6565
.store(in: &cancellables)
6666
workspace.$navigatorFilter
6767
.throttle(for: 0.1, scheduler: RunLoop.main, latest: true)
68-
.sink { [weak self] _ in self?.controller?.handleFilterChange() }
68+
.sink { [weak self] _ in
69+
self?.controller?.handleFilterChange()
70+
}
6971
.store(in: &cancellables)
70-
workspace.$sourceControlFilter
72+
Publishers.Merge(workspace.$sourceControlFilter, workspace.$sortFoldersOnTop)
7173
.throttle(for: 0.1, scheduler: RunLoop.main, latest: true)
72-
.sink { [weak self] _ in self?.controller?.handleFilterChange() }
74+
.sink { [weak self] _ in
75+
self?.controller?.handleFilterChange()
76+
}
7377
.store(in: &cancellables)
7478
}
7579

CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorViewController+NSOutlineViewDataSource.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,29 @@ extension ProjectNavigatorViewController: NSOutlineViewDataSource {
1212
private func getOutlineViewItems(for item: CEWorkspaceFile) -> [CEWorkspaceFile] {
1313
if let cachedChildren = filteredContentChildren[item] {
1414
return cachedChildren
15+
.sorted { lhs, rhs in
16+
workspace?.sortFoldersOnTop == true ? lhs.isFolder && !rhs.isFolder : lhs.name < rhs.name
17+
}
1518
}
1619

17-
if let children = workspace?.workspaceFileManager?.childrenOfFile(item) {
18-
if let filter = workspace?.navigatorFilter, let sourceControlFilter = workspace?.sourceControlFilter,
19-
!filter.isEmpty || sourceControlFilter {
20+
if let workspace, let children = workspace.workspaceFileManager?.childrenOfFile(item) {
21+
if !workspace.navigatorFilter.isEmpty || workspace.sourceControlFilter {
2022
let filteredChildren = children.filter {
21-
fileSearchMatches(filter, for: $0, sourceControlFilter: sourceControlFilter)
23+
fileSearchMatches(
24+
workspace.navigatorFilter,
25+
for: $0,
26+
sourceControlFilter: workspace.sourceControlFilter
27+
)
2228
}
29+
2330
filteredContentChildren[item] = filteredChildren
2431
return filteredChildren
2532
}
2633

2734
return children
35+
.sorted { lhs, rhs in
36+
workspace.sortFoldersOnTop ? lhs.isFolder && !rhs.isFolder : lhs.name < rhs.name
37+
}
2838
}
2939

3040
return []

CodeEdit/Features/NavigatorArea/ProjectNavigator/ProjectNavigatorToolbarBottom.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ struct ProjectNavigatorToolbarBottom: View {
2727
text: $workspace.navigatorFilter,
2828
leadingAccessories: {
2929
FilterDropDownIconButton(menu: {
30-
Button {
31-
workspace.sortFoldersOnTop.toggle()
32-
} label: {
33-
Text(workspace.sortFoldersOnTop ? "Alphabetically" : "Folders on top")
30+
ForEach([(true, "Folders on top"), (false, "Alphabetically")], id: \.0) { value, title in
31+
Toggle(title, isOn: Binding(get: {
32+
workspace.sortFoldersOnTop == value
33+
}, set: { _ in
34+
// Avoid calling the handleFilterChange method
35+
if workspace.sortFoldersOnTop != value {
36+
workspace.sortFoldersOnTop = value
37+
}
38+
}))
3439
}
3540
}, isOn: !workspace.navigatorFilter.isEmpty)
3641
.padding(.leading, 4)

0 commit comments

Comments
 (0)