Skip to content

Commit

Permalink
feat: trigger keystroke on ctrl-k
Browse files Browse the repository at this point in the history
  • Loading branch information
thephez committed Oct 7, 2024
1 parent 9130762 commit 7e84125
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions _static/js/pydata-search-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,37 @@ var addEventListenerForSearchKeyboard = () => {
window.addEventListener(
"keydown",
(event) => {
console.log(event.code)
// Allow Escape key to hide the search field
if (event.code == "Escape") {
hideSearchField();
}

// Open the new search modal by simulating "/" keypress when Ctrl+K is pressed
if (event.ctrlKey && event.key === 'k') {
console.log('ctrl+k was pressed')
event.preventDefault(); // Prevent default behavior of Ctrl+K
simulateSlashKeyPress();
}
},
true
);
};

/** Function to simulate pressing the "/" key */
var simulateSlashKeyPress = () => {
console.log("pressing '/'")
const slashKeyEvent = new KeyboardEvent("keydown", {
key: '/',
keyCode: 191,
code: "Slash",
which: 191,
bubbles: true,
cancelable: true
});
window.dispatchEvent(slashKeyEvent);
};

/** Activate callbacks for search button popup */
var setupSearchButtons = () => {
addEventListenerForSearchKeyboard();
Expand Down

0 comments on commit 7e84125

Please sign in to comment.