Skip to content

Commit 206b863

Browse files
boubakerexo-swf
authored andcommitted
feat: Allow to access Apps Shortcuts using a custom event - MEED-9220 - Meeds-io/meeds#3357 (#4875)
This change will make it possible to access App Center Shortcuts using custom event propagation rather than Keyboard events.
1 parent 2e222e1 commit 206b863

File tree

1 file changed

+18
-8
lines changed
  • webapp/src/main/webapp/vue-apps/common/js

1 file changed

+18
-8
lines changed

webapp/src/main/webapp/vue-apps/common/js/Utils.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,26 @@ export function addShortcutsListener(chars, listener) {
117117
chars.forEach(c => shortcutChars.add(c));
118118
window.addEventListener('keydown', e => {
119119
if (e.ctrlKey && e.shiftKey && e.key) {
120-
const c = e?.key?.toLowerCase?.();
121-
if (chars?.includes?.(c) && shortcutChars.has(c)) {
122-
e.stopPropagation();
123-
e.preventDefault();
124-
window.setTimeout(() => {
125-
listener(e.key);
126-
}, 10);
127-
}
120+
execShortcut(chars, listener, e);
128121
}
129122
});
123+
window.addEventListener('key-down', event => {
124+
const e = event?.detail;
125+
if (e?.key) {
126+
execShortcut(chars, listener, e);
127+
}
128+
});
129+
}
130+
131+
export function execShortcut(chars, listener, e) {
132+
const c = e?.key?.toLowerCase?.();
133+
if (chars?.includes?.(c) && shortcutChars.has(c)) {
134+
e?.stopPropagation?.();
135+
e?.preventDefault?.();
136+
window.setTimeout(() => {
137+
listener(e.key);
138+
}, 10);
139+
}
130140
}
131141

132142
export function removeShortcutsListener(chars) {

0 commit comments

Comments
 (0)