Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@codemirror/search

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/search

Search functionality for the CodeMirror code editor

  • 6.5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2M
increased by11.1%
Maintainers
2
Weekly downloads
 
Created

What is @codemirror/search?

@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.

What are @codemirror/search's main functionalities?

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 });

Other packages similar to @codemirror/search

Keywords

FAQs

Package last updated on 22 Nov 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc