Skip to content

Commit

Permalink
allow searching for atoms inside backticks (#1960)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SteffenDE authored Oct 31, 2024
1 parent a4cb212 commit 6197d18
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions assets/js/search-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 6197d18

Please sign in to comment.