Skip to content

Commit

Permalink
Merge branch 'develop' into fix/issue-5692
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkav committed Aug 30, 2023
1 parent 345eb49 commit dd5e377
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions packages/insomnia/src/ui/components/codemirror/code-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(({
}
});

codeMirror.current.on('keydown', (_: CodeMirror.Editor, event: KeyboardEvent) => {
codeMirror.current.on('keydown', (doc: CodeMirror.Editor, event: KeyboardEvent) => {
const pressedKeyComb: KeyCombination = {
ctrl: event.ctrlKey,
alt: event.altKey,
Expand All @@ -363,19 +363,18 @@ export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(({
event.codemirrorIgnore = true;
} else {
event.stopPropagation();
}
});
codeMirror.current.on('keyup', (doc: CodeMirror.Editor, event: KeyboardEvent) => {
// Enable graphql completion if we're in that mode
if (doc.getOption('mode') === 'graphql') {
// Only operate on one-letter keys. This will filter out
// any special keys (Backspace, Enter, etc)
const isModifier = event.metaKey || event.ctrlKey || event.altKey || event.key.length > 1;
// You don't want to re-trigger the hint dropdown if it's already open
// for other reasons, like forcing its display with Ctrl+Space
const isDropdownActive = codeMirror.current?.isHintDropdownActive();
if (!isModifier && !isDropdownActive) {
doc.execCommand('autocomplete');

// Enable graphql completion if we're in that mode
if (doc.getOption('mode') === 'graphql') {
// Only operate on one-letter keys. This will filter out
// any special keys (Backspace, Enter, etc)
const isModifier = event.metaKey || event.ctrlKey || event.altKey || event.key.length > 1;
// You don't want to re-trigger the hint dropdown if it's already open
// for other reasons, like forcing its display with Ctrl+Space
const isDropdownActive = codeMirror.current?.isHintDropdownActive();
if ((isAutoCompleteBinding || !isModifier) && !isDropdownActive) {
doc.execCommand('autocomplete');
}
}
}
});
Expand Down

0 comments on commit dd5e377

Please sign in to comment.