Skip to content

feat(files): find in an open markdown document with Cmd/Ctrl+F - #7196

Merged
waleedlatif1 merged 2 commits into
stagingfrom
feat/files-cmd-f-find
Aug 28, 2026
Merged

feat(files): find in an open markdown document with Cmd/Ctrl+F#7196
waleedlatif1 merged 2 commits into
stagingfrom
feat/files-cmd-f-find

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Cmd/Ctrl+F now opens find-in-document on an open markdown file, using the shared FindBar (Files page, mothership file view, public share page)
  • A ProseMirror plugin owns the match set and paints inline decorations — the search adds no document steps, so it never touches the markdown, the undo history, or the collaborative Y.Doc, and it re-searches on every document change so a highlight can't point at a range an edit removed
  • Matching delegates to the shared forEachSearchOccurrence instead of adding a fourth private definition of "an occurrence"; that also inherits the whitespace fold, so a typed space matches a non-breaking one
  • Fixes a latent bug in that shared helper: it normalized case with a plain toLowerCase(), which can grow a string (a few code points lowercase to two characters) and slide every later index, breaking its documented guarantee that bounds index the caller's own string. Now folds case length-preservingly, which also fixes workflow search and the canvas Note card
  • The Cmd/Ctrl+F open shortcut was a fourth byte-identical copy of the same effect — extracted to a shared useFindShortcut beside FindBar, which the Files list now uses too, with the one-owner-at-a-time invariant documented in one place

Type of Change

  • New feature

Testing

Tested via unit tests — 19 new tests covering match positions across mark boundaries, inline atoms, and length-changing lowercase, plus plugin behavior against a real TipTap editor (decoration painting, stepping/wrapping, re-search on edit, active-index clamping, and no document/selection/undo writes). Each new test verified to fail when its fix is reverted.

Full suite green: 865 tests across the file viewer, collab-doc converter and share page; 39 utils tests; bun run lint (26/26), bun run check:audits (37/37), bun run type-check, and check-block-registry all pass.

Not verified in a browser.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Adds find-in-document to the rich markdown editor, reusing the shared FindBar.
A ProseMirror plugin owns the match set and paints inline decorations, so the
search never touches the document, the undo history, or the collaborative Y.Doc,
and it re-searches on every document change so a highlight can't go stale.

Occurrence semantics come from the shared forEachSearchOccurrence rather than a
fourth private definition. That helper normalized case with a plain
toLowerCase(), which can grow a string and slide every later index, breaking its
documented guarantee that bounds index the caller's own string; it now folds
case length-preservingly for all three consumers.

The Cmd/Ctrl+F open shortcut was a fourth copy of the same effect. It moves to a
shared useFindShortcut beside FindBar, which the Files list now uses too.
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview Aug 28, 2026 3:35am

Request Review

@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds find-in-document support to markdown viewers while keeping search state outside document and collaboration history.

  • Adds a shared Cmd/Ctrl+F shortcut hook across Files, mothership, and public-file surfaces.
  • Adds a ProseMirror plugin for finding, highlighting, navigating, and refreshing markdown matches.
  • Makes shared case-insensitive occurrence matching preserve source-string offsets.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/find/find-extension.ts Adds transaction-metadata-driven search state and inline decorations without modifying editor content.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/find/find-matches.ts Flattens text blocks, finds bounded occurrences, and maps match offsets back to ProseMirror positions.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/find/use-markdown-find.ts Connects shortcut, query, navigation, tally synchronization, and active-match scrolling to the editor plugin.
apps/sim/app/workspace/[workspaceId]/components/find-bar/use-find-shortcut.ts Centralizes document-level Cmd/Ctrl+F handling behind explicit surface ownership.
packages/utils/src/string.ts Preserves caller-string offsets while applying case-insensitive search normalization.

Sequence Diagram

sequenceDiagram
  actor User
  participant Shortcut as useFindShortcut
  participant Bar as FindBar
  participant Hook as useMarkdownFind
  participant Plugin as RichMarkdownFind
  participant Doc as ProseMirror document
  User->>Shortcut: Cmd/Ctrl+F
  Shortcut->>Hook: open()
  Hook->>Bar: render and focus input
  User->>Bar: enter query
  Bar->>Hook: setQuery(query)
  Hook->>Plugin: dispatch query metadata
  Plugin->>Doc: scan visible text
  Plugin-->>Hook: matches and active index
  Hook-->>Bar: update tally
  User->>Bar: next or previous
  Bar->>Hook: step match
  Hook->>Plugin: dispatch active index
  Plugin-->>Doc: update decorations
Loading

Reviews (2): Last reviewed commit: "fix(files): close three find edge cases ..." | Re-trigger Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 17 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/utils/src/string.ts
- Keep context-sensitive lowercasing in the length-preserving case fold. A
  word-final sigma lowercases differently in a string than on its own, so
  folding character by character let one unrelated expanding code point change
  how every sigma in the string matched. The fallback now reads each
  character's replacement out of the whole-string result.
- Decline Cmd/Ctrl+F while a collaborative document is still seeding. The text
  on screen then belongs to the read-only placeholder's editor, not the empty
  hidden one find is attached to, so the bar answered "No results" for visible
  text. The browser's native find reads the placeholder correctly in that
  window; the shortcut becomes ours once the seed lands.
- Re-apply a pending term when the editor instance arrives, so a query typed
  before TipTap mounts is searched instead of sitting at zero matches until the
  next keystroke.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
waleedlatif1 merged commit b01b41f into staging Aug 28, 2026
25 of 26 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/files-cmd-f-find branch August 28, 2026 03:34
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