Skip to content

feat: add regex search mode to the search bar - #34

Merged
pedrosousa13 merged 3 commits into
mainfrom
feat/regex-search
Jun 25, 2026
Merged

feat: add regex search mode to the search bar#34
pedrosousa13 merged 3 commits into
mainfrom
feat/regex-search

Conversation

@pedrosousa13

@pedrosousa13 pedrosousa13 commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Regex search demo

What

Adds a regex toggle (.*) to the tree search bar. When enabled, the typed query is compiled to a case-insensitive RegExp and a node matches when the pattern tests true against its searchKey, searchPath, or searchValue. The regex: boolean flag is plumbed through the entire search path:

  • tree-worker-protocol.tsregex added to the search request shape
  • content.ts — toggle UI, sends the flag, validates the pattern, shows an inline error
  • tree-worker.ts — matching loop passes the flag through and skips normalization for regex
  • tree-search.ts — new compileSearchRegex helper + regex match branch alongside the existing substring scoring
  • tree-worker-client.ts — sync fallback honors the flag too

Why

Substring search can't express alternation, anchors, or character classes. Regex mode gives power users precise matching across keys, paths, and values without leaving the search bar.

Behavior notes

  • Regex uses the i flag, so matching is case-insensitive. The query is passed verbatim in regex mode (not trimmed/lowercased) since metacharacters and escapes are case-sensitive.
  • Invalid patterns are caught at compile time, surfaced as an inline Invalid regex status, and never sent to the worker — no crash, no worker spam. Fixing the pattern clears the error.
  • The toggle applies to tree search; the table view filter stays substring-only.

Known limitation

The search index lowercases values and truncates them at 200 chars (existing SEARCH_VALUE_PREVIEW_LIMIT behavior). A regex therefore only ever sees that truncated, lowercased text. Documented in a code comment on compileSearchRegex.

Test evidence

npm run typecheck — clean.

npm test — 12 files, 121 tests passing. New coverage:

  • src/tree-search.test.ts — regex matches across key/path/value, case-insensitivity, alternation, invalid regex handled gracefully (no throw → empty result), and substring mode unchanged (metacharacters treated literally when off).
  • src/tree-worker-client.test.ts — worker request carries the regex flag (defaults to false); sync fallback honors it.

npm run build — succeeds (dist/content.js, dist/tree-worker.js, dist/content.css).

npm run test:e2e20 tests passing including the new e2e/regex-search.spec.ts: toggling regex on, matching via alternation, stepping through hits, and the invalid-regex inline error path. No regressions in existing specs.

Try it

  • jsonplaceholder.typicode.com/comments — open search (⌘F/Ctrl+F), enable the .* toggle, try @\w+\.biz or ^lau → highlighted matches + counter, step with Enter/Shift+Enter.
  • Invalid pattern (e.g. [) → inline "Invalid regex" error, no crash.
  • Note: long values are truncated at 200 chars in the search index, so regex only sees the truncated text.

Add a `.*` toggle to the tree search bar that switches matching to a
case-insensitive regular expression. The regex flag is threaded through
the whole search path: protocol message, content UI, worker loop, the
scoring matcher, and the worker-client sync fallback.

Invalid patterns are caught and surfaced as an inline "Invalid regex"
status without crashing or sending the bad query to the worker. Regex
matches are tested against searchKey, searchPath, and searchValue.

Known limitation: the search index lowercases values and truncates them
at 200 chars, so a regex only ever sees that truncated, lowercased text.
@pedrosousa13
pedrosousa13 merged commit e48e4df into main Jun 25, 2026
2 checks passed
@pedrosousa13
pedrosousa13 deleted the feat/regex-search branch June 25, 2026 07:07
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