pybitesbooks icon indicating copy to clipboard operation
pybitesbooks copied to clipboard

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

Open bbelderbos opened this issue 1 year ago • 2 comments

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

bbelderbos avatar Jan 25 '24 16:01 bbelderbos

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

dundermain avatar Feb 01 '24 13:02 dundermain

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();
        }
    }
});

bbelderbos avatar Feb 01 '24 15:02 bbelderbos