MCPcopy
hub / github.com/tinymce/tinymce / parseShortcut

Function parseShortcut

modules/tinymce/src/core/main/ts/api/Shortcuts.ts:73–126  ·  view source on GitHub ↗
(pattern: string)

Source from the content-addressed store, hash-verified

71 key in modifierNames;
72
73const parseShortcut = (pattern: string): Shortcut => {
74 const shortcut = {} as Shortcut;
75 const isMac = Env.os.isMacOS() || Env.os.isiOS();
76
77 // Parse modifiers and keys ctrl+alt+b for example
78 each(explode(pattern.toLowerCase(), '+'), (value) => {
79 if (isModifier(value)) {
80 shortcut[value] = true;
81 } else {
82 // Allow numeric keycodes like ctrl+219 for ctrl+[
83 if (/^[0-9]{2,}$/.test(value)) {
84 shortcut.keyCode = parseInt(value, 10);
85 } else {
86 shortcut.charCode = value.charCodeAt(0);
87 shortcut.keyCode = keyCodeLookup[value] || value.toUpperCase().charCodeAt(0);
88 }
89 }
90 });
91
92 // Generate unique id for modifier combination and set default state for unused modifiers
93 const id: Array<string | number> = [ shortcut.keyCode ];
94 let key: keyof ModifierMap;
95 for (key in modifierNames) {
96 if (shortcut[key]) {
97 id.push(key);
98 } else {
99 shortcut[key] = false;
100 }
101 }
102 shortcut.id = id.join(',');
103
104 // Handle special access modifier differently depending on Mac/Win
105 if (shortcut.access) {
106 shortcut.alt = true;
107
108 if (isMac) {
109 shortcut.ctrl = true;
110 } else {
111 shortcut.shift = true;
112 }
113 }
114
115 // Handle special meta modifier differently depending on Mac/Win
116 if (shortcut.meta) {
117 if (isMac) {
118 shortcut.meta = true;
119 } else {
120 shortcut.ctrl = true;
121 shortcut.meta = false;
122 }
123 }
124
125 return shortcut;
126};
127
128class Shortcuts {
129 private readonly editor: Editor;

Callers

nothing calls this directly

Calls 3

explodeFunction · 0.85
isModifierFunction · 0.85
eachFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…