Skip to content

TUI only displays the first text fragment when a file contains multiple matches #74

Description

@shouze

What version of github-code-search is running?

v1.6.0

What steps can reproduce the bug?

Run a query that returns a file with multiple occurrences of the search term, so that the GitHub Code Search API returns several text_matches entries for the same file (same path within the same repository).

github-code-search query "somePattern" --org myorg

Open the TUI and navigate to a repository that has a file with multiple matching fragments. That file will show a single row in the TUI.

What is the expected behavior?

All fragments (text_matches) returned by the GitHub API for a given file should be displayed in the TUI, one after the other, so the user can see every matching code excerpt.

What do you see instead?

Only the first fragment (textMatches[0]) is rendered. Any additional fragments coming from the same file are silently ignored.

Additional information

Root cause (two locations):

  1. src/render.ts — the extract rendering block only iterates over match.textMatches[0]:

    if (match.textMatches.length > 0) {
      const tm = match.textMatches[0];   // ← only first fragment rendered
      // ...
    }
  2. src/render/rows.ts — rowTerminalLines() computes the terminal height for a row using only textMatches[0].fragment, so even the viewport height calculation is wrong for multi-fragment files:

    const rawLines = match.textMatches[0].fragment.split("\n");
    return 1 + Math.min(rawLines.length, MAX_FRAGMENT_LINES + 1);

Both sites need to be updated to iterate over all textMatches entries.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions