Home / Function/ subscribeKeyEvents() — react Function Reference

subscribeKeyEvents() — react Function Reference

Architecture documentation for the subscribeKeyEvents() function in runner-watch.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  6449f3d6_f157_1b29_f37a_a1faad31e9e1["subscribeKeyEvents()"]
  3c2dde8c_5e90_a277_13bd_39083b18cadb["runner-watch.ts"]
  6449f3d6_f157_1b29_f37a_a1faad31e9e1 -->|defined in| 3c2dde8c_5e90_a277_13bd_39083b18cadb
  7865a05e_4feb_a8ba_40fe_4675700de39b["makeWatchRunner()"]
  7865a05e_4feb_a8ba_40fe_4675700de39b -->|calls| 6449f3d6_f157_1b29_f37a_a1faad31e9e1
  711bc253_d799_dc69_d704_cfb793a8f199["renderAutocomplete()"]
  6449f3d6_f157_1b29_f37a_a1faad31e9e1 -->|calls| 711bc253_d799_dc69_d704_cfb793a8f199
  4bde4ec0_48d3_f978_b35d_bcdb20497109["filterFixtures()"]
  6449f3d6_f157_1b29_f37a_a1faad31e9e1 -->|calls| 4bde4ec0_48d3_f978_b35d_bcdb20497109
  35f5a65c_e6e8_8fa8_f9c0_158316bd8913["getFixtures()"]
  6449f3d6_f157_1b29_f37a_a1faad31e9e1 -->|calls| 35f5a65c_e6e8_8fa8_f9c0_158316bd8913
  style 6449f3d6_f157_1b29_f37a_a1faad31e9e1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/snap/src/runner-watch.ts lines 282–414

function subscribeKeyEvents(
  state: RunnerState,
  onChange: (state: RunnerState) => void,
) {
  process.stdin.on('keypress', async (str, key) => {
    // Handle input mode (pattern entry with autocomplete)
    if (state.inputMode !== 'none') {
      if (key.name === 'return') {
        // Enter pressed - use selected fixture or typed text
        let pattern: string;
        if (
          state.selectedIndex >= 0 &&
          state.selectedIndex < state.matchingFixtures.length
        ) {
          pattern = state.matchingFixtures[state.selectedIndex];
        } else {
          pattern = state.inputBuffer.trim();
        }

        state.inputMode = 'none';
        state.inputBuffer = '';
        state.allFixtureNames = [];
        state.matchingFixtures = [];
        state.selectedIndex = -1;

        if (pattern !== '') {
          state.filter = {paths: [pattern]};
          state.mode.filter = true;
          state.mode.action = RunnerAction.Test;
          onChange(state);
        }
        return;
      } else if (key.name === 'escape') {
        // Cancel input mode
        state.inputMode = 'none';
        state.inputBuffer = '';
        state.allFixtureNames = [];
        state.matchingFixtures = [];
        state.selectedIndex = -1;
        // Redraw normal UI
        onChange(state);
        return;
      } else if (key.name === 'up' || (key.name === 'tab' && key.shift)) {
        // Navigate up in autocomplete list
        if (state.matchingFixtures.length > 0) {
          if (state.selectedIndex <= 0) {
            state.selectedIndex =
              Math.min(state.matchingFixtures.length, MAX_DISPLAY) - 1;
          } else {
            state.selectedIndex--;
          }
          renderAutocomplete(state);
        }
        return;
      } else if (key.name === 'down' || (key.name === 'tab' && !key.shift)) {
        // Navigate down in autocomplete list
        if (state.matchingFixtures.length > 0) {
          const maxIndex =
            Math.min(state.matchingFixtures.length, MAX_DISPLAY) - 1;
          if (state.selectedIndex >= maxIndex) {
            state.selectedIndex = 0;
          } else {
            state.selectedIndex++;
          }
          renderAutocomplete(state);
        }
        return;
      } else if (key.name === 'backspace') {
        if (state.inputBuffer.length > 0) {
          state.inputBuffer = state.inputBuffer.slice(0, -1);
          state.matchingFixtures = filterFixtures(
            state.allFixtureNames,
            state.inputBuffer,
          );
          state.selectedIndex = -1;
          renderAutocomplete(state);
        }
        return;
      } else if (str && !key.ctrl && !key.meta) {
        // Regular character - accumulate, filter, and render
        state.inputBuffer += str;

Domain

Subdomains

Called By

Frequently Asked Questions

What does subscribeKeyEvents() do?
subscribeKeyEvents() is a function in the react codebase, defined in compiler/packages/snap/src/runner-watch.ts.
Where is subscribeKeyEvents() defined?
subscribeKeyEvents() is defined in compiler/packages/snap/src/runner-watch.ts at line 282.
What does subscribeKeyEvents() call?
subscribeKeyEvents() calls 3 function(s): filterFixtures, getFixtures, renderAutocomplete.
What calls subscribeKeyEvents()?
subscribeKeyEvents() is called by 1 function(s): makeWatchRunner.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free