Samasaur1 / samasaur1.github.io

the jekyll source for my website
https://samasaur1.github.io/
3 stars 0 forks source link

Allow ⌘F to search on page #8

Closed Samasaur1 closed 3 years ago

Samasaur1 commented 3 years ago

Currently, we intercept ⌘F (and ^F on non-macOS) and redirect it to our search field. However, this means that people cannot search on the page. Maybe we should do what GitHub does and use / as the search shortcut. If we replace this: https://github.com/Samasaur1/samasaur1.github.io/blob/473bf355327ff96eddeaa6c94862bfdf134e80c7/_includes/navigation.html#L44-L51 with the following JavaScript:

window.addEventListener("keydown", function(e) { 
  if (e.keyCode === 191) {
    e.preventDefault(); 
    document.getElementById("search-field").focus(); 
  }
});

then / selects the search field, but doesn't type into it. We'd need to only sometimes use e.preventDefault(), depending on whether the search field was selected, but that should be doable.

We should also have the little hint that GitHub has in its search bar that shows that / selects it.

Samasaur1 commented 3 years ago

Or maybe use ⇧⌘F?