MCPcopy
hub / github.com/graphql/graphiql / runAtCursor

Function runAtCursor

packages/graphiql-react/src/editor/query-editor.ts:408–438  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

406
407 const run = executionContext?.run;
408 const runAtCursor = () => {
409 if (
410 !run ||
411 !queryEditor ||
412 !queryEditor.operations ||
413 !queryEditor.hasFocus()
414 ) {
415 run?.();
416 return;
417 }
418
419 const cursorIndex = queryEditor.indexFromPos(queryEditor.getCursor());
420
421 // Loop through all operations to see if one contains the cursor.
422 let operationName: string | undefined;
423 for (const operation of queryEditor.operations) {
424 if (
425 operation.loc &&
426 operation.loc.start <= cursorIndex &&
427 operation.loc.end >= cursorIndex
428 ) {
429 operationName = operation.name?.value;
430 }
431 }
432
433 if (operationName && operationName !== queryEditor.operationName) {
434 setOperationName(operationName);
435 }
436
437 run();
438 };
439
440 useKeyMap(queryEditor, ['Cmd-Enter', 'Ctrl-Enter'], runAtCursor);
441 useKeyMap(queryEditor, ['Shift-Ctrl-C'], copy);

Callers

nothing calls this directly

Calls 2

setOperationNameFunction · 0.85
runFunction · 0.50

Tested by

no test coverage detected