Socket
Socket
Sign inDemoInstall

@codemirror/state

Package Overview
Dependencies
0
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @codemirror/state

Editor state data structures for the CodeMirror code editor


Version published
Weekly downloads
1.2M
decreased by-1.38%
Maintainers
2
Install size
426 kB
Created
Weekly downloads
 

Package description

What is @codemirror/state?

The @codemirror/state package is part of the CodeMirror (version 6) ecosystem, which provides a flexible, extensible text editor. This particular package is responsible for managing the state of the editor, including the document content, selection, and any other state that plugins might add. It allows for the creation, modification, and querying of editor state, facilitating complex text editing features.

What are @codemirror/state's main functionalities?

Creating an Editor State

This feature allows for the initialization of an editor state with a starting document. The document can be a string or a more complex structure for representing text.

{
  import {EditorState} from '@codemirror/state';
  const state = EditorState.create({doc: 'Hello, world!'});
}

Updating the State

This demonstrates how to update the state by creating a transaction. In this example, the text 'Hello' is replaced with 'Goodbye'. Transactions can include changes to the document, selections, and other state aspects.

{
  import {EditorState, Transaction} from '@codemirror/state';
  let newState = state.update({changes: {from: 0, to: 5, insert: 'Goodbye'}}).state;
}

Reading the State

This feature is about accessing the current content of the editor. It shows how to convert the document in the state to a string, which can be useful for saving the content or displaying it elsewhere.

{
  import {EditorState} from '@codemirror/state';
  const content = state.doc.toString();
}

Other packages similar to @codemirror/state

Changelog

Source

6.4.1 (2024-02-19)

Bug fixes

Fix an issue that caused widgets at the end of a mark decoration to be rendered in their own separate mark DOM element.

Readme

Source

@codemirror/state NPM version

[ WEBSITE | DOCS | ISSUES | FORUM | CHANGELOG ]

This package implements the editor state data structures 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.

Keywords

FAQs

Last updated on 19 Feb 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc