UNPKG

prism-code-editor

Version:

Lightweight, extensible code editor component for the web using Prism

54 lines (53 loc) 2.08 kB
import { BasicExtension, PrismEditor } from '../../types.js'; /** * Hotkey where the data parameter is an editor. */ export type EditorHotkey<T extends {} = {}> = Hotkey<PrismEditor<T>>; /** * Hotkeys are functions that are called when a specific key is pressed. When given data * and a keyboard event, it first checks if the side-effect should be performed with the * current state and event. If yes, `true` should be returned to signal the event was * handled. */ export type Hotkey<T> = (data: T, e: KeyboardEvent, key: string) => void | boolean; /** Object mapping keys to buckets of hotkeys. */ export type HotkeyMap<T> = Partial<Record<string, (Set<Hotkey<T>> | undefined)[]>>; export type HotkeySequenceOptions = { /** Maximum number of milliseconds allowed between steps. @default 2000 */ timeout?: number; /** * Precedence of the handler that starts the sequence. * @default 2 */ precedence?: number; /** * Whether or not to call `preventDefault()` when the sequence is advanced. This does * not apply to the final step where the return value of the command dictates whether * `preventDefault()` is called. * @default true */ preventDefault?: boolean; }; export interface EditHistory extends BasicExtension { /** Clears the history stack. */ clear(): void; /** * Sets the active entry relative to the current entry. * * @param offset The position you want to move to relative to the current entry. * * `EditHistory.go(-1)` would be equivalent to an undo while `EditHistory.go(1)` would * be equivalent to a redo. * * If there's no entry at the specified offset, the call does nothing. */ go(offset: number): void; /** * Returns whether or not there exists a history entry at the specified offset relative * to the current entry. * * This method can be used to determine whether a call to {@link EditHistory.go} with the * same offset will succeed or do nothing. */ has(offset: number): boolean; }