Skip to content

Commit

Permalink
vdoc: Enable browser custom search with ?q=<search>
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Lewis <[email protected]>
  • Loading branch information
gmlewis committed Mar 3, 2024
1 parent ac9b724 commit 5c16d41
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/tools/vdoc/theme/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ function setupDarkMode() {
}

function setupSearch() {
const searchInput = document.getElementById('search');
const onInputChange = debounce((e) => {
const searchValue = e.target.value.toLowerCase();
const docNav = document.querySelector('.doc-nav');
Expand Down Expand Up @@ -160,7 +159,18 @@ function setupSearch() {
});
}
});
searchInput.addEventListener('input', onInputChange);
const searchInput = document.querySelector('#search input');
const url = document.location.toString();
if (url.includes('?')) {
const query = url.split('?').slice(1).filter(p => p.startsWith('q=')).map(p => p.replace(/^q=/, ''))[0] || '';
if (query) {
searchInput.value = query;
searchInput.focus();
onInputChange({ target: { value: query }});
}
}
const searchInputDiv = document.getElementById('search');
searchInputDiv.addEventListener('input', onInputChange);
setupSearchKeymaps();
}

Expand Down

0 comments on commit 5c16d41

Please sign in to comment.