Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@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.
6.5.7 (2024-11-01)
Fix an issue where findNext
and findPrevious
would do nothing when the only match in the document was partially selected.
Fix an infinite loop in SearchCursor
when the normalizer function deletes characters.
FAQs
Search functionality for the CodeMirror code editor
The npm package @codemirror/search receives a total of 985,028 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.