From 976aed16b26e3c1968e338d38d2f4b30f8145a17 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Thu, 23 Jun 2022 22:33:01 +1000 Subject: In search results, make matched substrings bold --- src/components/SearchModal.vue | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/components/SearchModal.vue b/src/components/SearchModal.vue index af6aca5..bb58cbb 100644 --- a/src/components/SearchModal.vue +++ b/src/components/SearchModal.vue @@ -32,6 +32,28 @@ export default defineComponent({ margin: this.uiOpts.infoIconMargin + 'px', }; }, + suggDisplayStrings(): [string, string, string][] { + let result = []; + let input = this.$refs.searchInput.value; + // For each SearchSugg + for (let sugg of this.searchSuggs){ + let idx = sugg.name.indexOf(input); + // Split suggestion text into parts before/within/after an input match + let strings; + if (idx != -1){ + strings = [sugg.name.substring(0, idx), input, sugg.name.substring(idx + input.length)]; + } else { + strings = [input, '', '']; + } + // Indicate a distinct canonical-name + if (sugg.canonicalName != null){ + strings[2] += ` (aka ${sugg.canonicalName})`; + } + // + result.push(strings); + } + return result; + }, }, methods: { onCloseClick(evt: Event){ @@ -178,10 +200,12 @@ export default defineComponent({ :style="{backgroundColor: idx == focusedSuggIdx ? '#a3a3a3' : 'white'}" class="border p-1 hover:underline hover:cursor-pointer" @click="resolveSearch(sugg.canonicalName || sugg.name)"> + {{suggDisplayStrings[idx][0]}} + {{suggDisplayStrings[idx][1]}} + {{suggDisplayStrings[idx][2]}} - {{sugg.canonicalName == null ? sugg.name : `${sugg.name} (aka ${sugg.canonicalName})`}}
...
-- cgit v1.2.3