Skip to content

fix: a search of only spaces is no search - #378

Merged
brtkwr merged 1 commit into
mainfrom
fix/whitespace-search
Nov 22, 2026
Merged

brtkwr merged 1 commit into
mainfrom
fix/whitespace-search

Conversation

@brtkwr

@brtkwr brtkwr commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Opus 5.5 ✨

What was weird

Typing a single space in the search box (or several, or a tab) was treated as a search that matches everything but still ranks the results. I reproduced it by running ccs on made-up sessions in a throwaway HOME, as demo/record.py does, and typing a space:

  • The list reordered. A session with a title ranks above one without, so an untitled session from 20 minutes ago dropped to the very bottom, below sessions from 2 and 3 days ago. With an empty search it sits near the top, newest started first.
  • The preview cut the conversation. It switched to "search" mode, showing only the first and last two messages with gaps, though nothing matched.
  • ? stopped opening help, typing a ? into the box instead.

Some places already trimmed the query (whether HITS shows, the reorg-run filter) and others didn't (the filter, ranking, the preview, hit jumps, ?), so they disagreed.

The fix

searchQuery() in ui.go is the search box with the spaces around it trimmed, and every place that reads the search goes through it: updateFilter (and its HasPrefix narrowing), MatchRank via the filter, hitCount, the preview (previewLines, renderPreview, previewMessageRows), jumpHit, hideReorgRuns, the ? help key, the hidden sidebar's width, and the ^] ^\ hint. searching() is now searchQuery() != "". buildPreview also trims what it's handed, so it agrees whoever calls it.

One real change for padded words: the live tick re-matched a changed session with strings.Contains(searchLower, query), a substring of the whole query, so with " foo " (or "foo bar" with the words apart) a session that had just received a message could drop out of the results. It now uses transcript.QueryMatches, the same word rule as updateFilter.

ccs mcp search_sessions already matched with strings.Fields, so a query of only spaces was already rejected as empty and padding found the same sessions. But its reply repeated the query as typed (… sessions match " deploy "), so mcpSearch now trims the query first too.

Left as they were on purpose: the checks that protect typing in progress (a held menu giving up its keys, auto-select, auto-focus of the message box, the reorg popup, the orchestrator offer, Esc clearing the box, restoring the box after an update). Those read the raw box, so a typed space still counts as typing there.

Tests

  • TestSpacesAloneAreNoSearch: for " ", " ", "\t" and " \t ", the order (newest started first), ranks, HITS, the preview, buildPreviewLines, jumpHit, the hidden sidebar and ? help are the same as with an empty search.
  • TestPaddedSearchMatchesUnpadded: " deploy ", "\tdeploy" and "deploy " give the same order, ranks, HITS and preview as "deploy", and after the same live-tick update they keep the same sessions (with the old substring match a padded search dropped the updated one).
  • TestMCPSearchTrimsSpaces: search_sessions gives the empty-query error for spaces alone and the same output for padded words.

After the fix, the reproduction's screens with a space typed and with an empty box are identical, and " flaky " matches "flaky" exactly.

🤖 Generated with Claude Code

@brtkwr
brtkwr enabled auto-merge November 22, 2026 02:37
Typing a space in the search box was read as a search that matched every
session but still ranked them, so named sessions jumped above untitled ones
and the preview showed only the first and last messages with gaps. Every
place that reads the search now goes through searchQuery(), the box with
the spaces around it trimmed: the filter and its narrowing, ranking, HITS,
the preview and its hit jumps, the reorg-run filter, ? help, the hidden
sidebar and the live tick's re-match, which now uses the same word rule as
the filter instead of a substring of the whole query. ccs mcp's
search_sessions trims its query too, so its reply names "foo", not "  foo ".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brtkwr
brtkwr force-pushed the fix/whitespace-search branch from 737238f to 8d0479d Compare November 22, 2026 02:39
@brtkwr
brtkwr merged commit 0483abf into main Nov 22, 2026
1 check passed
@brtkwr
brtkwr deleted the fix/whitespace-search branch November 22, 2026 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant