0.3.1 • Published 5 months ago

codemirror-helix v0.3.1

Weekly downloads
-
License
MPL-2.0
Repository
gitlab
Last release
5 months ago

codemirror-helix

A Codemirror plugin for Helix keybindings and general UX.

Installation

npm install codemirror-helix

How to

import { EditorView } from "@codemirror/view";
import { helix, commands } from "codemirror-helix";

const customCommands = commands.of([
  {
    name: "save",
    aliases: ["s", "sv"],
    help: "Save the document to the cloud",
    handler(view, args) {
      saveDocumentToCloud(view.state.doc.toString());
    },
  },
]);

const view = new EditorView({
  doc: "",
  extensions: [helix(), customCommands],
  parent: document.querySelector("#editor"),
});

External commands

This plugin only augments the behavior of a single editor element, a single "tab". Some Helix commands, however, only make sense in a "project" context, where there are multiple files to edit, search, etc. The externalCommands facet allows you to define callbacks for these multi-editor commands:

import { EditorView } from "@codemirror/view";
import { helix, externalCommands } from "codemirror-helix";

const view = new EditorView({
  doc: "",
  extensions: [
    helix(),
    externalCommands.of({
      file_picker() {
        showFilePicker();
      },
      global_search(input: string) {
        seachProjectAndShowResults(input);
      },
      // ...
    }),
  ],
  parent: document.querySelector("#editor"),
});

In a multi-editor setup, you will probably need to sync some global state between editors (for instance, the values of the registers). You can either:

  • Serialize the state of an editor (with snapshot()) and pass it as initial state to helix(), or
  • Create a set of transactions using globalStateSync() and dispatch them into another editor.

See the code for the playground in demo/main.ts for an example of a multi-editor setup.

License

Mozilla Public License 2.0

0.3.0

5 months ago

0.3.1

5 months ago

0.2.0

9 months ago

0.1.0

11 months ago

0.0.9

12 months ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.5

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago