mirror of
https://github.com/Kong/insomnia.git
synced 2026-05-19 14:23:03 -04:00
feat: add hotKey to close tab (#8494)
This commit is contained in:
@@ -35,6 +35,7 @@ export const keyboardShortcutDescriptions: Record<KeyboardShortcut, string> = {
|
||||
'environment_showVariableSourceAndValue': 'Show variable source and value',
|
||||
'beautifyRequestBody': 'Beautify Active Code Editors',
|
||||
'graphql_explorer_focus_filter': 'Focus GraphQL Explorer Filter',
|
||||
'close_tab': 'Close Tab',
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -163,6 +164,10 @@ const defaultRegistry: HotKeyRegistry = {
|
||||
macKeys: [{ shift: true, meta: true, keyCode: keyboardKeys.i.keyCode }],
|
||||
winLinuxKeys: [{ ctrl: true, shift: true, keyCode: keyboardKeys.i.keyCode }],
|
||||
},
|
||||
close_tab: {
|
||||
macKeys: [{ meta: true, keyCode: keyboardKeys.w.keyCode }],
|
||||
winLinuxKeys: [{ ctrl: true, keyCode: keyboardKeys.w.keyCode }],
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,7 +55,8 @@ export type KeyboardShortcut =
|
||||
| 'request_togglePin'
|
||||
| 'environment_showVariableSourceAndValue'
|
||||
| 'beautifyRequestBody'
|
||||
| 'graphql_explorer_focus_filter';
|
||||
| 'graphql_explorer_focus_filter'
|
||||
| 'close_tab';
|
||||
|
||||
/**
|
||||
* The collection of defined hotkeys.
|
||||
|
||||
@@ -9,6 +9,7 @@ import type { RequestGroup } from '../../models/request-group';
|
||||
import type { UnitTestSuite } from '../../models/unit-test-suite';
|
||||
import type { WebSocketRequest } from '../../models/websocket-request';
|
||||
import type { Workspace } from '../../models/workspace';
|
||||
import { useDocBodyKeyboardShortcuts } from '../components/keydown-binder';
|
||||
import { type BaseTab, type TabType } from '../components/tabs/tab';
|
||||
import { TAB_ROUTER_PATH } from '../components/tabs/tab-list';
|
||||
import { formatMethodName, getRequestMethodShortHand } from '../components/tags/method-tag';
|
||||
@@ -38,7 +39,7 @@ export const useInsomniaTab = ({
|
||||
unitTestSuite,
|
||||
}: InsomniaTabProps) => {
|
||||
|
||||
const { appTabsRef, addTab, changeActiveTab } = useInsomniaTabContext();
|
||||
const { appTabsRef, addTab, changeActiveTab, closeTabById } = useInsomniaTabContext();
|
||||
const location = useLocation();
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
@@ -288,4 +289,14 @@ export const useInsomniaTab = ({
|
||||
}
|
||||
}
|
||||
}, [addTab, appTabsRef, changeActiveTab, getCurrentTab, location.pathname, organizationId, packTabInfo]);
|
||||
|
||||
useDocBodyKeyboardShortcuts({
|
||||
close_tab: event => {
|
||||
event.preventDefault();
|
||||
const currentActiveTabId = appTabsRef?.current?.[organizationId]?.activeTabId;
|
||||
if (currentActiveTabId) {
|
||||
closeTabById(currentActiveTabId);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user