MCPcopy
hub / github.com/directus/directus / useInlineCode

Function useInlineCode

app/src/interfaces/input-rich-text-html/useInlineCode.ts:20–64  ·  view source on GitHub ↗
(editor: Ref<any>)

Source from the content-addressed store, hash-verified

18}
19
20export default function useInlineCode(editor: Ref<any>): UsableInlineCode {
21 let keydownHandler: ((event: KeyboardEvent) => void) | null = null;
22
23 const inlineCodeButton: InlineCodeButton = {
24 tooltip: i18n.global.t('wysiwyg_options.codeblock'),
25 icon: 'code-sample',
26
27 onAction: () => {
28 editor.value.execCommand('mceToggleFormat', false, 'code');
29 },
30
31 onSetup: (api) => {
32 const updateActiveState = () => {
33 const isInlineCode = editor.value.formatter.match('code');
34
35 api.setActive(isInlineCode);
36 };
37
38 updateActiveState();
39
40 const codeFormatChangedUnbind = editor.value.formatter.formatChanged('code', updateActiveState).unbind;
41
42 keydownHandler = (event: KeyboardEvent) => {
43 const currentNode = editor.value.selection.getNode();
44 if (!isInlineCode(currentNode)) return;
45
46 if (event.key === 'Enter') {
47 event.preventDefault();
48
49 editor.value.execCommand('removeformat');
50 updateActiveState();
51 }
52 };
53
54 editor.value.on('keydown', keydownHandler);
55
56 return () => {
57 if (codeFormatChangedUnbind) codeFormatChangedUnbind();
58 if (keydownHandler) editor.value.off('keydown', keydownHandler);
59 };
60 },
61 };
62
63 return { inlineCodeButton };
64}

Callers

nothing calls this directly

Calls 4

isInlineCodeFunction · 0.85
onMethod · 0.80
offMethod · 0.80
updateActiveStateFunction · 0.70

Tested by

no test coverage detected