-
Notifications
You must be signed in to change notification settings - Fork 109
feat: show all icons alphabetically on empty search #210
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,9 @@ function filterIconIndex({ | |
|
|
||
| if (searchText.length < 3) { | ||
| if (selectedPack === PACK_FILTER_ALL) { | ||
| return []; | ||
| return iconIndex | ||
| .sort((a, b) => a.displayName.localeCompare(b.displayName)) | ||
| .slice(0, SEARCH_RESULT_LIMIT); | ||
| } | ||
|
Comment on lines
37
to
45
|
||
|
|
||
| return iconIndex | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,14 +102,15 @@ export default function NerdFontSearch() { | |
|
|
||
| const displayIcons = useMemo(() => { | ||
| if (searchText.length === 0 && activePack === PACK_FILTER_ALL) { | ||
| return recentIcons.map((icon) => ({ | ||
| ...icon, | ||
| keywords: [], | ||
| markdown: "", | ||
| })); | ||
| } | ||
| if (searchText.length < 3 && activePack === PACK_FILTER_ALL) { | ||
| return []; | ||
| // Show recent icons if available, otherwise show all icons | ||
| if (recentIcons.length > 0) { | ||
| return recentIcons.map((icon) => ({ | ||
| ...icon, | ||
| keywords: [], | ||
| markdown: "", | ||
| })); | ||
| } | ||
| return searchResults; | ||
| } | ||
| return searchResults; | ||
| }, [searchText, activePack, recentIcons, searchResults]); | ||
|
|
@@ -163,22 +164,16 @@ export default function NerdFontSearch() { | |
| title={ | ||
| searchText.length > 0 && searchText.length < 3 | ||
| ? "Keep typing..." | ||
| : searchText.length === 0 && activePack !== PACK_FILTER_ALL | ||
| : searchText.length >= 3 | ||
| ? "No icons found" | ||
| : searchText.length >= 3 | ||
| ? "No icons found" | ||
| : "Start searching" | ||
| : "Loading icons..." | ||
| } | ||
| description={ | ||
| searchText.length > 0 && searchText.length < 3 | ||
| ? "Enter at least 3 characters to search" | ||
| : searchText.length === 0 && activePack !== PACK_FILTER_ALL | ||
| ? "Try selecting another icon pack" | ||
| : searchText.length >= 3 | ||
| ? "Try a different search term or pick another icon pack" | ||
| : recentIcons.length > 0 | ||
| ? "Your recently copied icons will appear here" | ||
| : "Enter at least 3 characters to search for icons" | ||
| : searchText.length >= 3 | ||
| ? "Try a different search term or pick another icon pack" | ||
| : "Your icon library is loading. Please wait..." | ||
|
||
| } | ||
| icon={Icon.MagnifyingGlass} | ||
| /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,7 +31,11 @@ test("pack filter behavior for short and full search terms", () => { | |||||||||||||||||||
| searchText: "", | ||||||||||||||||||||
| selectedPack: PACK_FILTER_ALL, | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| assert.equal(noSearchAll.length, 0, "all-pack short search should return []"); | ||||||||||||||||||||
| assert.ok(noSearchAll.length > 0, "all-pack short search should return all icons"); | ||||||||||||||||||||
| assert.ok( | ||||||||||||||||||||
| noSearchAll.every((a, i, arr) => i === 0 || a.displayName >= arr[i - 1].displayName), | ||||||||||||||||||||
|
Comment on lines
+34
to
+36
|
||||||||||||||||||||
| assert.ok(noSearchAll.length > 0, "all-pack short search should return all icons"); | |
| assert.ok( | |
| noSearchAll.every((a, i, arr) => i === 0 || a.displayName >= arr[i - 1].displayName), | |
| assert.ok(noSearchAll.length > 0, "all-pack short search should return icons"); | |
| assert.ok( | |
| noSearchAll.every( | |
| (icon, i, arr) => | |
| i === 0 || arr[i - 1].displayName.localeCompare(icon.displayName) <= 0 | |
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iconIndex.sort(...)mutates the sharediconIndexarray in-place. Since the same array is cached (cachedIconIndex) and also passed into the Fuse instance (new Fuse(decodedIndex, ...)), this can reorder the underlying list after Fuse has been constructed and can lead to incorrect search results or hard-to-debug state issues. Use a non-mutating approach (e.g., sort a shallow copy) so the cached index and Fuse’s backing array aren’t modified.