Skip to content

refactor(search): one definition of what a search occurrence is - #6905

Merged
icecrasher321 merged 1 commit into
stagingfrom
fix/search-occurrence-parity
Aug 20, 2026
Merged

icecrasher321 merged 1 commit into
stagingfrom
fix/search-occurrence-parity

Conversation

@icecrasher321

Copy link
Copy Markdown
Contributor

Follow-up to #6901. Two places where the workflow search index and the Note card that mirrors it could drift apart. Neither is a live bug — both are the shape that produced one during that PR's review, where the card silently disagreed with the panel about which hit was which.

1. The scan was duplicated

#6901 shared foldSearchWhitespace but left the loop around it written out twice — normalize, then non-overlapping indexOf stepping by max(len, 1) — once in findTextRanges and once in the renderer package.

They agree today. They stop agreeing the moment either grows whole-word matching, diacritic folding, or a regex mode, and the failure mode is silent: the panel counts a hit the card marks somewhere else. That is exactly the bug Bugbot caught in #6901, in its whitespace-folding form; sharing only the fold fixed the instance and left the mechanism.

Both now call one forEachSearchOccurrence in @sim/utils/string. That is the only place they can share it: the card renders from @sim/workflow-renderer, and packages cannot import from apps/*.

2. The markdown declaration was unpinned

The indexer projects markdown escapes only when a field declares searchTextFormat: 'markdown'. The card projects unconditionally — it has no access to the block registry. Removing that one line from the Note config would leave the two disagreeing about what an occurrence is, with nothing to catch it.

A test now pins the declaration and explains the coupling. Verified it fails when the line is removed.

Notes for review

  • Net −2 lines. This deletes a duplicated loop; it does not add a layer.
  • forEachNoteSearchOccurrence is gone from the renderer package — it was a wrapper around the duplicate. Callers use the shared primitive directly.
  • Case sensitivity stays where it was: the shared scanner takes the flag, the indexer passes it, the card does not (the search panel is the only caller and never enables it). Now that the algorithm is in one place, anyone plumbing it through will see both callers at once rather than having to know a second copy exists.

Testing

@sim/utils 160, @sim/workflow-renderer 104, apps/sim search-replace + panel 132 — all pass. Both type-checks, check:api-validation, monorepo boundaries and biome clean.

The new parity test was checked for vacuousness: deleting searchTextFormat from blocks/blocks/note.ts makes it fail.

🤖 Generated with Claude Code

Loading
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