PyBites-Open-Source / pybitesbooks

27 stars 18 forks source link

activate the search field ("What are you reading") with a keyboard shortcut #88

Open bbelderbos opened 7 months ago

bbelderbos commented 7 months ago

Circle uses ⌘K to open search, but / would be nice too (my Vim bias)

dundermain commented 7 months ago

@bbelderbos Correct me if I am wrong, but does this require updating event keys and event listener? I think that is written in JS.

bbelderbos commented 7 months ago

Yes you would do this in JS, adding a document.addEventListener.

I did something similar for another project, maybe this helps:

document.addEventListener('keydown', function(event) {
    // Check if Command (for Mac) or Ctrl (for Windows/Linux) is pressed along with 'K'
    if ((event.metaKey || event.ctrlKey) && event.key === 'k') {
        // Prevent default action to ensure no other action is performed with the same shortcut
        event.preventDefault();

        // Get the search box by its ID and focus on it
        let searchBox = document.getElementById('search');
        if (searchBox) {
            searchBox.focus();
        }
    }
});