Skip to content

Commit ff43881

Browse files
committed
searchable in spotlight
1 parent d6e944e commit ff43881

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

CodeEdit/Features/Welcome/Views/RecentProjectsListView.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import SwiftUI
9+
import CoreSpotlight
910

1011
struct RecentProjectsListView: View {
1112

@@ -25,6 +26,20 @@ struct RecentProjectsListView: View {
2526
let projectsURL = recentProjectPaths.map { URL(filePath: $0) }
2627
_selection = .init(initialValue: Set(projectsURL.prefix(1)))
2728
_recentProjects = .init(initialValue: projectsURL)
29+
donateSearchableItems()
30+
}
31+
func donateSearchableItems() {
32+
let searchableItems = recentProjects.map { entity -> CSSearchableItem in
33+
let attributeSet = CSSearchableItemAttributeSet(contentType: .content)
34+
attributeSet.title = String(entity.lastPathComponent)
35+
attributeSet.relatedUniqueIdentifier = String(entity.path())
36+
return CSSearchableItem(
37+
uniqueIdentifier: String(entity.path()),
38+
domainIdentifier: "app.codeedit.CodeEdit.ProjectItem",
39+
attributeSet: attributeSet
40+
)
41+
}
42+
CSSearchableIndex.default().indexSearchableItems(searchableItems)
2843
}
2944

3045
var listEmptyView: some View {

0 commit comments

Comments
 (0)