Skip to content

Commit

Permalink
All recent projects searchable in Spotlight (#1680)
Browse files Browse the repository at this point in the history
* keyboard shortcut for tab switching

* extension and menu bar

* resolve swiftlint violations

* searchable in spotlight

* move function to bottom

* remove unneeded casting and add error handling

* remove CSSearchableItem type

* no success message, space between funcs, and no public func

* fix whitespace violation
  • Loading branch information
knotbin authored Apr 23, 2024
1 parent d1ee5ac commit 70cb34a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions CodeEdit/Features/Welcome/Views/RecentProjectsListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import CoreSpotlight

struct RecentProjectsListView: View {

Expand All @@ -25,6 +26,7 @@ struct RecentProjectsListView: View {
let projectsURL = recentProjectPaths.map { URL(filePath: $0) }
_selection = .init(initialValue: Set(projectsURL.prefix(1)))
_recentProjects = .init(initialValue: projectsURL)
donateSearchableItems()
}

var listEmptyView: some View {
Expand Down Expand Up @@ -118,4 +120,22 @@ struct RecentProjectsListView: View {
let projectsURL = recentProjectPaths.map { URL(filePath: $0) }
recentProjects = projectsURL
}

func donateSearchableItems() {
let searchableItems = recentProjects.map { entity in
let attributeSet = CSSearchableItemAttributeSet(contentType: .content)
attributeSet.title = entity.lastPathComponent
attributeSet.relatedUniqueIdentifier = entity.path()
return CSSearchableItem(
uniqueIdentifier: entity.path(),
domainIdentifier: "app.codeedit.CodeEdit.ProjectItem",
attributeSet: attributeSet
)
}
CSSearchableIndex.default().indexSearchableItems(searchableItems) { error in
if let error = error {
print(error)
}
}
}
}

0 comments on commit 70cb34a

Please sign in to comment.