Skip to content
Open
Changes from all commits
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
16 changes: 10 additions & 6 deletions Sources/SnippetStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,17 @@ class SnippetStore: ObservableObject {
}

func filtered(by query: String) -> [Snippet] {
let sorted = snippets.sorted { $0.useCount > $1.useCount }
guard !query.isEmpty else { return sorted }
// When there is no search query, honour the stored order so that
// manual drag-reordering (via move(from:to:)) is visible to the user.
// When filtering, sort by useCount so the most-used matches rise first.
guard !query.isEmpty else { return snippets }
let q = query.lowercased()
return sorted.filter {
$0.title.lowercased().contains(q) ||
$0.value.lowercased().contains(q)
}
return snippets
.filter {
$0.title.lowercased().contains(q) ||
$0.value.lowercased().contains(q)
}
.sorted { $0.useCount > $1.useCount }
}

func move(from source: IndexSet, to destination: Int) {
Expand Down