Welcome to mirror list, hosted at ThFree Co, Russian Federation.

external_keydown_handler.js « extensions « content_editor « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e48100c15a78904d6958774ac23379a155629580 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Extension } from '@tiptap/core';
import { Plugin, PluginKey } from '@tiptap/pm/state';
import { KEYDOWN_EVENT } from '../constants';

/**
 * This extension bubbles up the keydown event, captured by ProseMirror in the
 * contenteditale element, to the presentation layer implemented in vue.
 *
 * The purpose of this mechanism is allowing clients of the
 * content editor to attach keyboard shortcuts for behavior outside
 * of the Content Editor’s boundaries, i.e. submitting a form to save changes.
 */
export default Extension.create({
  name: 'keyboardShortcut',
  addOptions() {
    return {
      eventHub: null,
    };
  },
  addProseMirrorPlugins() {
    return [
      new Plugin({
        key: new PluginKey('keyboardShortcut'),
        props: {
          handleKeyDown: (_, event) => {
            const {
              options: { eventHub },
            } = this;

            eventHub.$emit(KEYDOWN_EVENT, event);

            return false;
          },
        },
      }),
    ];
  },
});