import { EditorState, Extension, Facet, type StateEffect, type Text, type TransactionSpec } from "@codemirror/state"; import { EditorView } from "@codemirror/view"; import { CommandPanelMessage } from "./panels"; type ExternalCommand = "file_picker" | "buffer_picker" | ":buffer-next" | ":buffer-previous"; type ExternalActionHandler = () => CommandPanelMessage | void; type ExternalCommandsDefinition = Partial> & { [":buffer-close"]?: { handler(buffers?: string[]): void | CommandPanelMessage; autocomplete?: (args: string[]) => string[]; }; global_search?(input: string): void | CommandPanelMessage; }; /** * A facet that allows to define external commands. */ declare const externalCommandsFacet: Facet; export { externalCommandsFacet as externalCommands }; /** * Exposes the contents of a given register for external consumption * for e.g. reading registers in external UI elements, suck as pickers. * * The special register '+' acts like a normal registry for the purposes * of this function. */ declare function externalReadRegister(state: EditorState, register: string): (string | Text)[] | undefined; export { externalReadRegister as readRegister }; /** * Allows the embedder to provide the "path" i.e. the contents of the `%` register. */ export declare const pathRegister: Facet; /** * A snapshot created by `snapshot()`. */ interface Snapshot { __brand: "snapshot_return_type"; } /** * Creates a snapshot of the extension state suitable to initialize * the extension later (see `init` and `globalInit`). Snapshots are JSON-serializable. * * If `global` is true, the snapshot only contains global state. This way * it is slimmer, but it is only valid for `globalInit`. */ export declare function snapshot(state: EditorState, global?: boolean): Snapshot; /** * Generates a list of transactions that can be dispatched to * another editor to ensure that its global state is synchronized * with `state`. */ export declare function globalStateSync(state: EditorState): TransactionSpec[]; /** * A facet to define typable commands. No effort is made to prevent overrides, * collisions, etc. */ export declare const commands: Facet; declare const exportedResetMode: StateEffect; /** * An effect to reset the mode of an editor. */ export { exportedResetMode as resetMode }; /** * A command that can be typed in command mode `:`. */ export interface TypableCommand { name: string; aliases?: string[]; help: string; autocomplete?: (args: string[]) => string[]; /** * The handler for the command. The return type can specify a message, * and qualify it as an error if desired. */ handler(view: EditorView, args: any[]): CommandPanelMessage | void; } export interface Options { config?: Config; /** * Themes accessible from the `:theme` command. */ themes?: Array<{ name: string; extension: Extension | (() => Promise); dark?: boolean; }>; /** * Whether to include the `drawSelection` extension. Defaults to `true`. * Set to `false` if you want to provide your own `drawSelection` * configuration or your CodeMirror environment already includes drawSelection * (e.g. Obsidian). */ drawSelection?: boolean; /** * If provided, sets the extension initial state from a previous state, or a snapshot * created by `snapshot()`. */ init?: EditorState | Snapshot; /** * Like `init`, but it will only restore global state that should be shared between different "tabs". * For instance, registers are global state, while undo/redo history is not. */ globalInit?: EditorState | Snapshot; } /** * Editor configuration. * The names follow Helix's options' naming. */ export interface Config { /** * If provided, it must be one of the themes provided in `Options.themes`. */ theme?: string; "editor.cursor-shape.insert"?: "block" | "bar"; "editor.default-yank-register"?: string; } declare const themeFacet: Facet<(theme: { name: string; dark?: boolean; }) => void, readonly ((theme: { name: string; dark?: boolean; }) => void)[]>; /** * Facet that allows to listen to theme changes. */ export { themeFacet as themeListener }; /** * Changes the theme of the editor. It needs to be pre-configured * in `themes` (see `Options`). */ export { changeThemeAction as changeTheme }; declare function changeThemeAction(view: EditorView, theme: string): void; /** * The main helix extension. * * It provides Helix-like keybindings, plus two panels to emulate the statusline and the commandline. */ export declare function helix(options?: Options): Extension;