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

Fixed/issue 5692 - Show autocomplete in GraphQL #5941

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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