KBARResults: Add Cmd+Enter/Ctrl+Enter to open links in new tab (#107537)

* KBARResults:add command+enter to open selected link in new tab
This commit is contained in:
Yunwen Zheng
2025-07-07 11:37:35 -04:00
committed by GitHub
parent 37c480def4
commit a2a28b207c
@@ -71,7 +71,18 @@ export const KBarResults = (props: KBarResultsProps) => {
}
return nextIndex;
});
} else if (event.key === 'Enter' && !event.metaKey) {
} else if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
// Cmd+Enter (Mac) or Ctrl+Enter (Windows/Linux) - open in new tab
event.preventDefault();
if (activeRef.current instanceof HTMLAnchorElement) {
window.open(activeRef.current.href, '_blank', 'noopener,noreferrer');
query.toggle();
} else {
// For action-based items (rendered as <div> tags), execute normally
activeRef.current?.click();
}
} else if (event.key === 'Enter' && !event.metaKey && !event.ctrlKey) {
event.preventDefault();
// storing the active dom element in a ref prevents us from
// having to calculate the current action to perform based