Skip to content

CodeMirror commands to expand/shrink text selections, inspired by Emacs’ expand-region and expreg.

License

Notifications You must be signed in to change notification settings

i-aki-y/codemirror-expand-selection

Repository files navigation

Expand Selection for CodeMirror

Expand/shrink text selections in CodeMirror 6 inspired by Emacs’ expand-region and expreg. This extension allows users to grow their current selection step by step (from cursor → word → syntax node → larger structures) and shrink it back when needed.

Installation

npm install codemirror-expand-selection

Usage

import { javascript } from "@codemirror/lang-javascript";
import { keymap } from "@codemirror/view";
import { basicSetup, EditorView } from "codemirror";
import {
  expandSelection,
  expandSelectionExtension,
  shrinkSelection,
  swapAnchorHead,
} from "codemirror-expand-selection";

const view = new EditorView({
  doc: "function helloWorld() { console.log('Hello!'); }",
  extensions: [
    basicSetup,
    expandSelectionExtension(), // enable expand/shrink selection
    keymap.of([
      { key: "Ctrl-Alt-Space", run: expandSelection },
      { key: "Ctrl-Alt-Shift-Space", run: shrinkSelection },
      { key: "Ctrl-t", run: swapAnchorHead },
    ]),
    javascript(),
  ],
  parent: document.body,
});

License

MIT

About

CodeMirror commands to expand/shrink text selections, inspired by Emacs’ expand-region and expreg.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors