From 27818151e78d2620b3a6d6b3db33a1aa3ec91218 Mon Sep 17 00:00:00 2001 From: Dark_Phoenix_ <92178883+0DarkPhoenix@users.noreply.github.com> Date: Sun, 30 Nov 2025 23:31:39 +0100 Subject: [PATCH] feat(unicode-search): Added ability to search using unicode characters (#213) Added the ability so search using unicode characters Changed English and Chinese translations of tag-gt-more-info translation key to remove an unparsed html > tag Changed indexed characterName by removing the unnecessary addition of "U+${hex})". To still show the Unicode hex part, it is now added to the 'name' column --- components.d.ts | 3 ++- locales/en.yml | 2 +- locales/zh.yml | 2 +- src/tools/unicode-search/unicode-search.vue | 21 ++++++++++++++++++--- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/components.d.ts b/components.d.ts index 955cd35d..1e35cfec 100644 --- a/components.d.ts +++ b/components.d.ts @@ -5,7 +5,7 @@ // Read more: https://github.com/vuejs/core/pull/3399 import '@vue/runtime-core' -export {} +export { } declare module '@vue/runtime-core' { export interface GlobalComponents { @@ -357,6 +357,7 @@ declare module '@vue/runtime-core' { MttdlCalculator: typeof import('./src/tools/mttdl-calculator/mttdl-calculator.vue')['default'] MultiLinkDownloader: typeof import('./src/tools/multi-link-downloader/multi-link-downloader.vue')['default'] MyIp: typeof import('./src/tools/my-ip/my-ip.vue')['default'] + NA: typeof import('naive-ui')['NA'] NanoidGenerator: typeof import('./src/tools/nanoid-generator/nanoid-generator.vue')['default'] NanoMemo: typeof import('./src/tools/nano-memo/nano-memo.vue')['default'] 'NanoMemo.content': typeof import('./src/tools/nano-memo/nano-memo.content.md')['default'] diff --git a/locales/en.yml b/locales/en.yml index 7b9bafde..73483f98 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -3236,7 +3236,7 @@ tools: tag-category: Category tag-html: Html tag-name: Name - tag-gt-more-info: '> More info' + tag-gt-more-info: 'More info about this character' url-cleaner: title: Url Cleaner description: >- diff --git a/locales/zh.yml b/locales/zh.yml index fa42e091..2b50480f 100644 --- a/locales/zh.yml +++ b/locales/zh.yml @@ -3075,7 +3075,7 @@ tools: tag-category: 类别 tag-html: HTML tag-name: 名称 - tag-gt-more-info: "> 更多信息" + tag-gt-more-info: '关于这个角色的更多信息' url-cleaner: title: URL清理器 description: | diff --git a/src/tools/unicode-search/unicode-search.vue b/src/tools/unicode-search/unicode-search.vue index 0699c155..193df594 100644 --- a/src/tools/unicode-search/unicode-search.vue +++ b/src/tools/unicode-search/unicode-search.vue @@ -21,6 +21,21 @@ function toUTF8(codePoint: number) { const searchQuery = useDebouncedRef('', 250); const parsedSearchQuery = computed(() => { + const trimmedQuery = searchQuery.value.trim(); + + // Check if input is a single character (or a multi-byte Unicode character) + if (trimmedQuery.length > 0) { + const firstCodePoint = trimmedQuery.codePointAt(0); + if (firstCodePoint != null) { + // If it's a single character, convert to hex for exact search + const charLength = firstCodePoint > 0xFFFF ? 2 : 1; + if (trimmedQuery.length === charLength) { + return `=${toPaddedHex(firstCodePoint)}`; + } + } + } + + // Check for various Unicode notation formats const parsedRegex = /^\s*(?:\&#x(?[\da-f]+);|\&#(?\d+);|(?:U\+|\\u)?\s*(?[\da-f]+))\s*$/gi; // NOSONAR const parsedQuery = parsedRegex.exec(searchQuery.value); if (parsedQuery) { @@ -31,6 +46,7 @@ const parsedSearchQuery = computed(() => { return `=${toPaddedHex(Number.parseInt(parsedQuery.groups.dec, 10))}`; } } + return searchQuery.value; }); @@ -38,13 +54,12 @@ const unicodeSearchData = [...unicodeNames].map(([codePoint, characterName]) => const hex = toPaddedHex(codePoint); return { codePoint, - characterName: `${characterName} (U+${hex})`, + characterName, hex, }; }); const limit = ref(40); -// Using FlexSearch instead of FuzzySearch for better performance const { searchResult } = useFlexSearch({ search: parsedSearchQuery, data: unicodeSearchData, @@ -119,7 +134,7 @@ const { searchResult } = useFlexSearch({ - +