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

@tidbcloud/codemirror-extension-events

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tidbcloud/codemirror-extension-events

codemirror extension to listen doc and selection changes event

  • 0.0.7
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@tidbcloud/codemirror-extension-events

2 normal kinds of codemirror event listener: doc change, selection change

  • onDocChange: triggered when doc changes
  • onSelectionChange: triggered when selection changes

Installation

npm install @tidbcloud/codemirror-extension-events

You need to install its peer dependencies as well:

npm install @codemirror/view @codemirror/state

Usage

import { EditorView } from '@codemirror/view'
import { EditorState } from '@codemirror/state'
import {
  onDocChange,
  onSelectionChange,
  SelectionRange
} from '@tidbcloud/codemirror-extension-events'

const docChangeHandler = (view: EditorView, state: EditorState, doc: string) => {
  console.log(doc)
}

const selectionChangeHandler = (view: EditorView, state: EditorState, ranges: SelectionRange[]) => {
  console.log(ranges)
}

const editorView = new EditorView({
  state: EditorState.create({
    doc,
    extensions: [
      onDocChange(docChangeHandler),
      onSelectionChange(selectionChangeHandler)
    ]
  })
})

API

type DocChangeHandler = (view: EditorView, state: EditorState, content: string) => void
function onDocChange(handler: DocChangeHandler): Extension

type SelectionRange = {
  from: number
  to: number
}
type SelectionChangeHandler = (
  view: EditorView,
  state: EditorState,
  selRanges: SelectionRange[]
) => void
function onSelectionChange(handler: SelectionChangeHandler): Extension

Keywords

FAQs

Package last updated on 10 Oct 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