Some checks failed
Publish codemirror-helix / publish (push) Failing after 2m16s
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { EditorState, type Extension } from "@codemirror/state";
|
|
import { search } from "@codemirror/search";
|
|
import { helixState, registersField } from "./state";
|
|
import { blockCursor, helixStatusPanel, helixTheme, modeEditorClass } from "./view";
|
|
import { helixPrompt } from "./prompt";
|
|
import { helixKeymap, type HelixOptions } from "./keymap";
|
|
|
|
export interface HelixConfig extends HelixOptions {
|
|
/** Render the bottom status line. Default: true. */
|
|
statusBar?: boolean;
|
|
/** Start the editor in Insert mode instead of Normal. Default: false. */
|
|
startInInsert?: boolean;
|
|
}
|
|
|
|
/**
|
|
* Helix-style modal editing for CodeMirror 6.
|
|
*
|
|
* Add to a CodeMirror instance's `extensions`. Requires a selection drawer
|
|
* (CodeMirror's `basicSetup` or `drawSelection()`) for multi-cursor rendering.
|
|
*
|
|
* ```ts
|
|
* import { basicSetup } from "codemirror";
|
|
* import { helix } from "codemirror-helix";
|
|
*
|
|
* new EditorView({ extensions: [basicSetup, helix()], parent });
|
|
* ```
|
|
*/
|
|
export function helix(config: HelixConfig = {}): Extension {
|
|
return [
|
|
EditorState.allowMultipleSelections.of(true),
|
|
helixState.init(() => ({
|
|
mode: config.startInInsert ? "insert" : "normal",
|
|
pending: null,
|
|
count: 0,
|
|
register: null,
|
|
lastFind: null,
|
|
})),
|
|
registersField,
|
|
search(),
|
|
helixKeymap(config),
|
|
blockCursor,
|
|
modeEditorClass,
|
|
helixTheme,
|
|
...(config.statusBar === false ? [] : [helixStatusPanel]),
|
|
helixPrompt,
|
|
];
|
|
}
|
|
|
|
export { getMode, getHelix, helixState } from "./state";
|
|
export type { HelixMode, HelixStateValue } from "./state";
|
|
export type { HelixOptions } from "./keymap";
|