Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bbelderbos opened this issue Jan 25, 2024 · 2 comments

Comments

@bbelderbos
Copy link
Collaborator

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

@dundermain
Copy link
Contributor

@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
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants