Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@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.
FAQs
Search functionality for the CodeMirror code editor
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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.