mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Better GraphQL query highlighting
This commit is contained in:
parent
3d73cfa2a8
commit
e12ae8f932
@ -110,19 +110,34 @@ class GraphQLEditor extends React.PureComponent<Props, State> {
|
||||
const cursor = _queryEditor.getCursor();
|
||||
const cursorIndex = _queryEditor.indexFromPos(cursor);
|
||||
|
||||
let operationName = null;
|
||||
let allOperationNames = [];
|
||||
|
||||
// Loop through all operations to see if one contains the cursor.
|
||||
for (let i = 0; i < operations.length; i++) {
|
||||
const operation = operations[i];
|
||||
if (
|
||||
operation.loc.start <= cursorIndex &&
|
||||
operation.loc.end >= cursorIndex &&
|
||||
operation.name
|
||||
) {
|
||||
return operation.name.value;
|
||||
|
||||
if (!operation.name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
allOperationNames.push(operation.name.value);
|
||||
|
||||
const { start, end } = operation.loc;
|
||||
if (start <= cursorIndex && end >= cursorIndex) {
|
||||
operationName = operation.name.value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
if (!operationName && operations.length > 0) {
|
||||
operationName = this.state.body.operationName || null;
|
||||
}
|
||||
|
||||
if (!allOperationNames.includes(operationName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return operationName;
|
||||
}
|
||||
|
||||
_handleQueryFocus() {
|
||||
|
Loading…
Reference in New Issue
Block a user