From 8c29d131e29fd0a66d8cb7756aa1459a42e83f01 Mon Sep 17 00:00:00 2001 From: David Coomber <47242934+dcoomber@users.noreply.github.com> Date: Sun, 19 Mar 2023 18:38:08 +0200 Subject: [PATCH] Proposed addition of CMD+W hotkey Re #128 --- .../bruno-app/src/providers/Hotkeys/index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/bruno-app/src/providers/Hotkeys/index.js b/packages/bruno-app/src/providers/Hotkeys/index.js index 553477609..31a6a79b3 100644 --- a/packages/bruno-app/src/providers/Hotkeys/index.js +++ b/packages/bruno-app/src/providers/Hotkeys/index.js @@ -10,6 +10,7 @@ import NewRequest from 'components/Sidebar/NewRequest'; import BrunoSupport from 'components/BrunoSupport'; import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions'; import { findCollectionByUid, findItemInCollection } from 'utils/collections'; +import { closeTabs } from 'providers/ReduxStore/slices/tabs'; export const HotkeysContext = React.createContext(); @@ -144,6 +145,23 @@ export const HotkeysProvider = (props) => { }; }, [setShowNewRequestModal]); + // close tab hotkey + useEffect(() => { + Mousetrap.bind(['command+w', 'ctrl+w'], (e) => { + dispatch( + closeTabs({ + tabUids: [activeTabUid] + }) + ); + + return false; // this stops the event bubbling + }); + + return () => { + Mousetrap.unbind(['command+w', 'ctrl+w']); + }; + }, [activeTabUid, tabs, collections, setShowNewRequestModal]); + return ( {showBrunoSupportModal && setShowBrunoSupportModal(false)} />}