From 5918f35b8bd65dafffb5fcf1146d1e13a2ce9d5b Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Sun, 13 Apr 2025 13:12:32 +0800 Subject: [PATCH] feat: Add keyboard shortcuts for search input focus and selection --- static/js/managers/SearchManager.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/static/js/managers/SearchManager.js b/static/js/managers/SearchManager.js index 49e6749b..46c9a247 100644 --- a/static/js/managers/SearchManager.js +++ b/static/js/managers/SearchManager.js @@ -29,6 +29,7 @@ export class SearchManager { this.initEventListeners(); this.loadSearchPreferences(); + this.setupKeyboardShortcuts(); updatePanelPositions(); @@ -36,6 +37,26 @@ export class SearchManager { window.addEventListener('resize', updatePanelPositions); } + // Add this new method to setup keyboard shortcuts + setupKeyboardShortcuts() { + // Add global keyboard shortcut listener for Ctrl+F or Cmd+F + document.addEventListener('keydown', (e) => { + // Check for Ctrl+F (Windows/Linux) or Cmd+F (Mac) + if ((e.ctrlKey || e.metaKey) && e.key === 'f') { + // Prevent default browser search behavior + e.preventDefault(); + + // Focus the search input if it exists + if (this.searchInput) { + this.searchInput.focus(); + + // Optionally select all text in the search input for easy replacement + this.searchInput.select(); + } + } + }); + } + initEventListeners() { // Search input event if (this.searchInput) {