@codemirror/search

Find, replace, regex search, and match highlighting for the CodeMirror 6 code editor.

Library
npm
v6.7.2
26 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
24 /100 Needs Attention
Development Activity 4
Maintenance 0
Community 20
Maturity 60
Momentum 12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
87 /100 Excellent
Architecture 88
Code Quality 85
Innovation 88
Learning Curve 58

@codemirror/search is the official search extension for CodeMirror 6, the extensible in-browser code editor. It adds an interactive search-and-replace panel, plain-string and regular-expression matching, whole-word and case-sensitive options, and live highlighting of the current selection’s occurrences across the document.

Beyond the ready-made panel, the package exposes composable editor commands and two standalone match-iterator classes — SearchCursor and RegExpCursor — that you can drive directly from your own UI or keymaps. It follows CodeMirror’s facet-and-extension model, so search state integrates cleanly with the rest of your editor configuration.

What You Get

  • A drop-in search panel with find, replace, replace-all, case-sensitivity, whole-word, and regular-expression toggles
  • A ready-made searchKeymap plus individual commands (findNext, findPrevious, replaceNext, replaceAll, openSearchPanel, gotoLine) you can bind however you like
  • SearchCursor and RegExpCursor iterator classes for scanning document text by string or regex, usable independently of the panel
  • Live selection-match highlighting via highlightSelectionMatches and multi-cursor selectNextOccurrence
  • An immutable SearchQuery value object and facet-based configuration for panel placement and default match options

Common Use Cases

  • Adding Ctrl/Cmd-F find-and-replace to a CodeMirror-based code or text editor in a web app
  • Building a bespoke search UI while reusing the underlying cursors and commands
  • Highlighting every occurrence of the current selection as the user moves through a document
  • Implementing editor-style ‘select next occurrence’ multi-cursor editing

Under The Hood

Architecture

The entry point src/search.ts exposes search(config?), which returns a CodeMirror Extension combining a searchConfigFacet with the core search extensions. Search state lives in a StateField mutated through StateEffects such as setSearchQuery, while editor Commands (findNext, findPrevious, replaceNext, replaceAll, openSearchPanel, closeSearchPanel) act on the EditorView/EditorState. The UI is a CodeMirror Panel shown via showPanel and assembled with the tiny crelt DOM helper. Text matching is cleanly separated into two iterator classes: SearchCursor (src/cursor.ts) performs buffered, NFKD-normalized plain-string scanning over a TextIterator, and RegExpCursor (src/regexp.ts) does line-oriented regular-expression matching. src/selection-match.ts supplies highlightSelectionMatches as a ViewPlugin that emits a DecorationSet, and src/goto-line.ts adds the go-to-line command. The result is a well-layered design: pure iterators feed a SearchQuery model, which drives state and commands, which the view renders.

Tech Stack

The package is written entirely in TypeScript and depends only on @codemirror/state (^6), @codemirror/view (^6.37), and crelt (^1) for DOM construction. It is ESM-first but ships dual builds (dist/index.js and dist/index.cjs) with bundled type declarations and sideEffects: false for tree-shaking. Builds run through @codemirror/buildhelper (cm-buildhelper) and tests through cm-runtests, keeping the dependency and tooling surface deliberately minimal.

Code Quality

The test/ directory covers the core primitives — test-cursor.ts, test-query.ts, and test-selection-match.ts — exercising string/regex matching, query parsing, and selection highlighting. Source files are small and focused, use strict TypeScript with readonly fields and explicit iterator interfaces, and carry /// doc comments on every public API that generate the reference docs. Regex validity is guarded via validRegExp. Test coverage concentrates on the matching engine rather than the panel/command UI.

API Design Developer experience is excellent within the CodeMirror ecosystem: a single search(config?) extension is the entry point, configured through a typed SearchConfig (panel placement, default case-sensitivity, literal, whole-word, regexp, custom createPanel, and scrollToMatch). Commands are exported individually so they compose into custom keymaps, SearchQuery is an immutable value object, and the SearchCursor/RegExpCursor classes are usable standalone outside the editor. Naming is consistent with CodeMirror 6 conventions; the main cost is the boilerplate required to author a fully custom panel.

Used by 35 apps in this directory

TypeScript
68%
MIT

Hoppscotch

Developer Tools

80,676

A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.

View details
91
Repo Health
83
Technical
62
Dependency
Built with
TypeScript 68%
Vue 24%
Updated 6 days ago
TypeScript
91%
Apache 2.0

HyperFrames

AI Design Tools · AI Development

70,938

Turn plain HTML and CSS into deterministic, pixel-perfect MP4 videos — authored by humans or AI agents, rendered by headless Chrome and FFmpeg.

View details
84
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 91%
Updated 5 days ago
TypeScript
100%
Apache 2.0

ILLA Builder

Design Tools · Developer Tools · Low Code Platforms

12,333

Open-source low-code platform for building internal tools with drag-and-drop UI, reactive data bindings, and real-time collaboration.

View details
55
Repo Health
71
Technical
63
Dependency
Built with
TypeScript 100%
Updated 5 months ago
TypeScript
77%
Other

Joplin

Note Taking

56,853

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
60
Dependency
Built with
TypeScript 77%
JavaScript 14%
Updated 6 days ago
TypeScript
52%

Kener

Devops · Monitoring

5,216

Stunning, self-hosted status pages with real-time uptime monitoring, incident management, and multi-channel notifications in a single Docker container.

View details
87
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 52%
Svelte 45%
Updated 1 weeks ago
TypeScript
63%
Apache 2.0

Laminar

AI Development · Monitoring

3,434

Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.

View details
86
Repo Health
76
Technical
65
Dependency
Built with
TypeScript 63%
Rust 35%
Updated 5 days ago
TypeScript
96%
Other

Langfuse

AI Development · Monitoring

36,276

Open source AI engineering platform for LLM observability, prompt management, evaluation, and debugging — self-host in minutes or use Langfuse Cloud.

View details
92
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 96%
Updated 5 days ago
Go
51%
AGPL 3.0

listmonk

Blogging · Marketing

23,944

High-performance, self-hosted newsletter and mailing list manager packaged as a single binary with built-in analytics, transactional messaging, and multi-channel delivery.

View details
90
Repo Health
74
Technical
64
Dependency
Built with
Go 51%
JavaScript 22%
HTML 20%
Updated 5 days ago
Python
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

23,309

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers