publish codemirrot helix package flow
Some checks failed
Publish codemirror-helix / publish (push) Failing after 2m16s
Some checks failed
Publish codemirror-helix / publish (push) Failing after 2m16s
This commit is contained in:
51
packages/codemirror-helix/src/index.ts
Normal file
51
packages/codemirror-helix/src/index.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
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";
|
||||
Reference in New Issue
Block a user