From 6197d189731bb83f0acbc2f8f15343d1835203fd Mon Sep 17 00:00:00 2001 From: Steffen Deusch Date: Thu, 31 Oct 2024 19:41:18 +0100 Subject: [PATCH] allow searching for atoms inside backticks (#1960) In the LV repo you were not able to search for atoms inside backticks, for example when searching for "validate_attrs" the corresponding option of the `Phoenix.Component.slot/3` macro could not be found. This commit fixes this by stripping the backticks from tokens and also removing trailing colons. --- assets/js/search-page.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/assets/js/search-page.js b/assets/js/search-page.js index 35768ace7..46e134a3a 100644 --- a/assets/js/search-page.js +++ b/assets/js/search-page.js @@ -161,6 +161,12 @@ function docTokenFunction (token) { const namespaceRegex = /\:|\./ let toSplitWords = token.toString() + // clean up leading and trailing backticks + if (toSplitWords.startsWith('`') && toSplitWords.endsWith('`')) { + toSplitWords = toSplitWords.slice(1, -1) + tokens.push(token.clone().update(() => toSplitWords)) + } + if (arityRegex.test(toSplitWords)) { const withoutArity = token .toString() @@ -188,6 +194,10 @@ function docTokenFunction (token) { // also make it searchable as foo_bar toSplitWords = toSplitWords.substring(1) tokens.push(token.clone().update(() => toSplitWords)) + } else if (toSplitWords.startsWith(':')) { + // allow searching for atoms without `:` + toSplitWords = toSplitWords.substring(1) + tokens.push(token.clone().update(() => toSplitWords)) } // Now split the function name (or the token, if that's all we had),