UNPKG

2.28 kBTypeScriptView Raw
1/**
2 * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4 */
5/**
6 * @module core/editingkeystrokehandler
7 */
8import { KeystrokeHandler, type PriorityString } from '@ckeditor/ckeditor5-utils';
9import type Editor from './editor/editor.js';
10/**
11 * A keystroke handler for editor editing. Its instance is available
12 * in {@link module:core/editor/editor~Editor#keystrokes} so plugins
13 * can register their keystrokes.
14 *
15 * E.g. an undo plugin would do this:
16 *
17 * ```ts
18 * editor.keystrokes.set( 'Ctrl+Z', 'undo' );
19 * editor.keystrokes.set( 'Ctrl+Shift+Z', 'redo' );
20 * editor.keystrokes.set( 'Ctrl+Y', 'redo' );
21 * ```
22 */
23export default class EditingKeystrokeHandler extends KeystrokeHandler {
24 /**
25 * The editor instance.
26 */
27 readonly editor: Editor;
28 /**
29 * Creates an instance of the keystroke handler.
30 */
31 constructor(editor: Editor);
32 /**
33 * Registers a handler for the specified keystroke.
34 *
35 * The handler can be specified as a command name or a callback.
36 *
37 * @param keystroke Keystroke defined in a format accepted by
38 * the {@link module:utils/keyboard~parseKeystroke} function.
39 * @param callback If a string is passed, then the keystroke will
40 * {@link module:core/editor/editor~Editor#execute execute a command}.
41 * If a function, then it will be called with the
42 * {@link module:engine/view/observer/keyobserver~KeyEventData key event data} object and
43 * a `cancel()` helper to both `preventDefault()` and `stopPropagation()` of the event.
44 * @param options Additional options.
45 * @param options.priority The priority of the keystroke callback. The higher the priority value
46 * the sooner the callback will be executed. Keystrokes having the same priority
47 * are called in the order they were added.
48 */
49 set(keystroke: string | Array<string | number>, callback: EditingKeystrokeCallback, options?: {
50 readonly priority?: PriorityString;
51 }): void;
52}
53/**
54 * Command name or a callback to be executed when a given keystroke is pressed.
55 */
56export type EditingKeystrokeCallback = string | ((ev: KeyboardEvent, cancel: () => void) => void);
57
\No newline at end of file