Skip to content

Commit

Permalink
Prevent cursor jumping to the beginning of the seach field when navig…
Browse files Browse the repository at this point in the history
…ating search results upwards
  • Loading branch information
doersino committed Mar 26, 2021
1 parent 01a7ec9 commit 1ac453c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions _assets/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ function highlightSearchSelection() {
searchInput.addEventListener('keydown', e => {
if (e.key == "ArrowUp") {
searchSelection = Math.max(-1, searchSelection - 1);
e.preventDefault();
} else if (e.key == "ArrowDown") {
searchSelection = Math.min(searchResultsCount - 1, searchSelection + 1);
e.preventDefault();
} else if (e.key == "Enter") {
if (searchSelection != -1) {
document.getElementById(`${searchSelection}`).click();
Expand Down
2 changes: 2 additions & 0 deletions _site/assets/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ function highlightSearchSelection() {
searchInput.addEventListener('keydown', e => {
if (e.key == "ArrowUp") {
searchSelection = Math.max(-1, searchSelection - 1);
e.preventDefault();
} else if (e.key == "ArrowDown") {
searchSelection = Math.min(searchResultsCount - 1, searchSelection + 1);
e.preventDefault();
} else if (e.key == "Enter") {
if (searchSelection != -1) {
document.getElementById(`${searchSelection}`).click();
Expand Down
2 changes: 1 addition & 1 deletion _site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h3>
</section>
<footer>
<p>Enjoy!</p>
<p class="updatedtime">Updated on 2021-03-25.</p>
<p class="updatedtime">Updated on 2021-03-26.</p>
</footer> </main>
</body>
</html>

0 comments on commit 1ac453c

Please sign in to comment.