Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shortcut): shortcut close env form #6518

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/insomnia/src/common/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const keyboardShortcutDescriptions: Record<KeyboardShortcut, string> = {
'request_send': 'Send Request',
'request_showOptions': 'Send Request (Options)',
'environment_showEditor': 'Show Environment Editor',
'environment_closeEditor': 'Close Environment Editor',
'environment_showSwitchMenu': 'Switch Environments',
'request_toggleHttpMethodMenu': 'Change HTTP Method',
'request_toggleHistory': 'Show Request History',
Expand Down Expand Up @@ -99,6 +100,10 @@ const defaultRegistry: HotKeyRegistry = {
macKeys: [{ meta: true, keyCode: keyboardKeys.e.keyCode }],
winLinuxKeys: [{ ctrl: true, keyCode: keyboardKeys.e.keyCode }],
},
environment_closeEditor: {
macKeys: [{ meta: true, shift: true, keyCode: keyboardKeys.s.keyCode }],
winLinuxKeys: [{ ctrl: true, shift: true, keyCode: keyboardKeys.s.keyCode }],
},
environment_showSwitchMenu: {
macKeys: [{ shift: true, meta: true, keyCode: keyboardKeys.e.keyCode }],
winLinuxKeys: [{ ctrl: true, shift: true, keyCode: keyboardKeys.e.keyCode }],
Expand Down
1 change: 1 addition & 0 deletions packages/insomnia/src/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type KeyboardShortcut =
| 'request_send'
| 'request_showOptions'
| 'environment_showEditor'
| 'environment_closeEditor'
| 'environment_showSwitchMenu'
| 'request_toggleHttpMethodMenu'
| 'request_toggleHistory'
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/ui/components/base/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const Modal = forwardRef<ModalHandle, ModalProps>(({

const handleKeydown = createKeybindingsHandler({
'Escape': () => {
hide();
containerRef.current?.focus();
},
});
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classnames from 'classnames';
import React, { FC, Fragment, useEffect, useRef } from 'react';
import React, { FC, Fragment, useEffect, useRef, KeyboardEvent } from 'react';
import { ListDropTargetDelegate, ListKeyboardDelegate, mergeProps, OverlayContainer, useDraggableCollection, useDraggableItem, useDropIndicator, useDroppableCollection, useDroppableItem, useFocusRing, useListBox, useOption } from 'react-aria';
import { useFetcher, useParams, useRouteLoaderData } from 'react-router-dom';
import { DraggableCollectionState, DroppableCollectionState, Item, ListState, useDraggableCollectionState, useDroppableCollectionState, useListState } from 'react-stately';
Expand All @@ -17,6 +17,7 @@ import { ModalHeader } from '../base/modal-header';
import { PromptButton } from '../base/prompt-button';
import { EnvironmentEditor, EnvironmentEditorHandle } from '../editors/environment-editor';
import { HelpTooltip } from '../help-tooltip';
import { useDocBodyKeyboardShortcuts } from '../keydown-binder';
import { Tooltip } from '../tooltip';

const ROOT_ENVIRONMENT_NAME = 'Base Environment';
Expand Down Expand Up @@ -244,6 +245,10 @@ export const WorkspaceEnvironmentsEditModal = (props: ModalProps) => {
modalRef.current?.show();
}, []);

useDocBodyKeyboardShortcuts({
environment_closeEditor: () => modalRef.current?.hide(),
});

if (!routeData) {
return null;
}
Expand Down Expand Up @@ -306,10 +311,16 @@ export const WorkspaceEnvironmentsEditModal = (props: ModalProps) => {
sourceEnv.metaSortKey = targetEnv.metaSortKey + 1;
}
updateEnvironment(sourceEnv._id, { metaSortKey: sourceEnv.metaSortKey });
}
};

const handleKeyDown = (event: KeyboardEvent): void => {
if (event.key === 'Enter') {
modalRef.current?.hide();
}
};

return (
<OverlayContainer>
<OverlayContainer onKeyDown={handleKeyDown} tabIndex={0}>
<Modal ref={modalRef} wide tall onHide={props.onHide}>
<ModalHeader>Manage Environments</ModalHeader>
<ModalBody noScroll className="env-modal">
Expand Down