This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A Tiptap V3+ search and replace plugin. Published as tiptap_search_replace_plugin on npm.
| Command | Purpose |
|---|---|
pnpm install |
Install dependencies |
pnpm build |
Build library (tsc) |
pnpm dev |
Watch mode build (tsc --watch) |
pnpm demo:deploy |
Deploy React demo to GitHub Pages |
The demo React app lives under demo/react/ — you must cd there and pnpm install separately to run it (pnpm dev in that directory).
The library has three source files in lib/:
-
lib/index.ts— TiptapExtension.create()that registers the ProseMirror plugin and exposes commands (find,findNext,findPrevious,replace,replaceAll,openFindReplace,closeFindReplace,toggleFindReplace). Commands dispatch actions viatr.setMeta(findReplacePluginKey, { action }). The extension also registers a keyboard shortcut (Mod-fby default, configurable viaopenPaneloption) and emits afindReplace:toggleFindReplaceevent. -
lib/findReplacePlugin.ts— Core ProseMirrorPluginmanaging state (query,matches,activeMatchIndex,isPanelOpen). Renders highlight decorations using CSS classesfind-replace-highlight(matches) andfind-replace-highlight-active(current match). HandlesEscapekey to close the panel. Actions:FIND,NAVIGATE,REPLACE,REPLACE_ALL,OPEN_PANEL,CLOSE_PANEL. -
lib/util.ts— ExportsnextTick(fn)(setTimeout 0 wrapper).
- User action → Tiptap command (e.g.,
find("text")) → dispatches action viatr.setMeta(findReplacePluginKey, { action }) - Plugin's
state.apply()processes the action, recomputes matches, returns new state - Plugin's
decorationsprop reads state and returnsDecorationSetwith inline highlight decorations NAVIGATEaction scrolls to the active match and setsTextSelection
- Match finding uses
doc.descendants()to walk all text nodes, case-insensitive search - Replace uses
tr.insertText();replaceAllprocesses matches in reverse order to avoid position drift - Replace/close operations use
nextTickto re-search after DOM update (avoids race conditions) - No bundled CSS — consumers style
.find-replace-highlightand.find-replace-highlight-activethemselves
No tests yet. The test script in package.json is a placeholder.