Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
@codemirror/search
Advanced tools
@codemirror/search is a package for the CodeMirror 6 text editor that provides search and replace functionality. It allows users to perform text searches, highlight search results, and replace text within the editor.
Basic Search
This code sets up a basic CodeMirror editor with the search functionality enabled. It demonstrates how to perform a basic search for the word 'sample' within the document.
import { searchKeymap, search } from '@codemirror/search';
import { EditorState, EditorView, basicSetup } from '@codemirror/basic-setup';
const state = EditorState.create({
doc: 'This is a sample document. You can search within this text.',
extensions: [basicSetup, searchKeymap]
});
const view = new EditorView({
state,
parent: document.body
});
// To perform a search
const searchQuery = search('sample');
view.dispatch({ effects: searchQuery });
Search and Replace
This code sets up a basic CodeMirror editor with search and replace functionality. It demonstrates how to replace the word 'sample' with 'example' within the document.
import { searchKeymap, replace } from '@codemirror/search';
import { EditorState, EditorView, basicSetup } from '@codemirror/basic-setup';
const state = EditorState.create({
doc: 'This is a sample document. You can replace text within this text.',
extensions: [basicSetup, searchKeymap]
});
const view = new EditorView({
state,
parent: document.body
});
// To perform a search and replace
const replaceQuery = replace('sample', 'example');
view.dispatch({ effects: replaceQuery });
Highlight Search Results
This code sets up a basic CodeMirror editor with search highlighting enabled. It demonstrates how to highlight the search results for the word 'sample' within the document.
import { searchKeymap, highlightSearch } from '@codemirror/search';
import { EditorState, EditorView, basicSetup } from '@codemirror/basic-setup';
const state = EditorState.create({
doc: 'This is a sample document. Highlighting search results is useful.',
extensions: [basicSetup, searchKeymap, highlightSearch()]
});
const view = new EditorView({
state,
parent: document.body
});
// To highlight search results
const searchQuery = search('sample');
view.dispatch({ effects: searchQuery });
The 'codemirror' package is the core library for the CodeMirror editor. It provides the basic text editor functionality but does not include advanced search and replace features out of the box. Additional functionality can be added through extensions like @codemirror/search.
The 'ace-builds' package is a standalone code editor similar to CodeMirror. It includes built-in search and replace functionality, but the API and customization options differ from those of CodeMirror. Ace is known for its performance and ease of integration.
The 'monaco-editor' package is the code editor that powers Visual Studio Code. It offers advanced search and replace features, along with many other functionalities. Monaco is highly customizable and provides a rich API, making it a strong alternative to CodeMirror.
[ WEBSITE | DOCS | ISSUES | FORUM | CHANGELOG ]
This package implements search functionality for the CodeMirror code editor.
The project page has more information, a number of examples and the documentation.
This code is released under an MIT license.
We aim to be an inclusive, welcoming community. To make that explicit, we have a code of conduct that applies to communication around the project.
0.17.0 (2020-12-29)
First numbered release.
FAQs
Search functionality for the CodeMirror code editor
The npm package @codemirror/search receives a total of 812,601 weekly downloads. As such, @codemirror/search popularity was classified as popular.
We found that @codemirror/search demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.