0.11.1 • Published 4 years ago

codemirror-addon-toggle-comment v0.11.1

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

CodeMirror Addon Toggle Comment

CodeMirror 5 does come with a comment addon, but I wanted to use the same algorithm used in Brackets

This addon is that: I ported the code related to commenting code from Brackets and experimented a bit, integrating features of the original one.

Used in Quadre editor.

How to install

The addon is released on npm so just run

npm install codeMirror-addon-toggle-comment

How to use

It defines two extensions: cm.toggleLineComment(options?) and cm.toggleBlockComment(options?).

Options

indent?: boolean

If false the comment will start at the start of the line, otherwise will try to match the indentation of the selected code.

padding?: string

A string that will be inserted after opening and before closing comment marker.

commentBlankLines?: boolean

Whether, when adding line comments, to also comment lines that contain only whitespace.

lineComment?: string | string[]

The strings used for commenting the code in case of line comment.

blockCommentStart?: string

The string used for commenting the code at the start of a block comment.

blockCommentEnd?: string

The string used for commenting the code at the end of a block comment.

getMode?: (mode, pos)

It returns an object with these properties: lineComment, blockCommentStart and blockCommentEnd. When this options is used the lineComment, blockCommentStart and blockCommentEnd options will be ignored.

Example:

codeMirror.toggleLineComment({
    indent: true,
    padding: " "
});

Differences in distributed files

  • toggle-comment-simple.js: this relies on CodeMirror but also on lodash 4, so you should install yourself

  • toggle-comment.js: this relies on CodeMirror, lodash code is already incorporated.

  • toggle-comment-simple.mjs: this relies on CodeMirror, lodash code is already incorporated. It is experimental for direct use in a ES6 code base.

0.11.0

4 years ago

0.11.1

4 years ago

0.10.0

4 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.1

6 years ago

0.1.0

6 years ago