Fix edition

This commit is contained in:
Paulo Gustavo Veiga 2022-04-05 15:49:43 -03:00
parent 4851da1f18
commit 7637c3ed31
2 changed files with 15 additions and 13 deletions

View File

@ -21,6 +21,11 @@ import Keyboard from './Keyboard';
import { Designer } from '..'; import { Designer } from '..';
import Topic from './Topic'; import Topic from './Topic';
import initHotKeyPluggin from '../../../../libraries/jquery.hotkeys';
// Provides dispatcher of keyevents by key...
initHotKeyPluggin($);
export type EventCallback = (event?: Event) => void; export type EventCallback = (event?: Event) => void;
class DesignerKeyboard extends Keyboard { class DesignerKeyboard extends Keyboard {
// eslint-disable-next-line no-use-before-define // eslint-disable-next-line no-use-before-define
@ -28,6 +33,8 @@ class DesignerKeyboard extends Keyboard {
private static _disabled: boolean; private static _disabled: boolean;
private static excludeFromEditor = ['Escape', 'F1', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12'];
constructor(designer: Designer) { constructor(designer: Designer) {
super(); super();
$assert(designer, 'designer can not be null'); $assert(designer, 'designer can not be null');
@ -150,18 +157,15 @@ class DesignerKeyboard extends Keyboard {
} }
}, },
); );
const excludes = ['Escape', 'F1', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12'];
$(document).on('keypress', (event) => { $(document).on('keypress', (event) => {
if (DesignerKeyboard.isDisabled()) { // Needs to be ignored ?
if (DesignerKeyboard.isDisabled() || DesignerKeyboard.excludeFromEditor.includes(event.code)) {
return; return;
} }
// Firefox doesn't skip special keys for keypress event...
if (excludes.includes(event.code)) { // Should I open the editor ?
return; if (!['Enter', 'CapsLock'].includes(event.code)) {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (['Enter', 'CapsLock'].includes(event.code)) {
const nodes = designer.getModel().filterSelectedTopics(); const nodes = designer.getModel().filterSelectedTopics();
if (nodes.length > 0) { if (nodes.length > 0) {
// If a modifier is press, the key selected must be ignored. // If a modifier is press, the key selected must be ignored.

View File

@ -22,15 +22,13 @@ import initHotKeyPluggin from '../../../../libraries/jquery.hotkeys';
initHotKeyPluggin($); initHotKeyPluggin($);
class Keyboard { class Keyboard {
addShortcut(shortcuts: string[] | string, callback: () => void, stopPropagation?: true) { addShortcut(shortcuts: string[] | string, callback: () => void) {
const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts]; const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts];
shortcutsArray.forEach((shortcut) => { shortcutsArray.forEach((shortcut) => {
$(document).bind('keydown', shortcut, $(document).bind('keydown', shortcut,
(e) => { (e) => {
if (stopPropagation) { e.stopPropagation();
e.stopPropagation(); e.preventDefault();
e.preventDefault();
}
callback(); callback();
}); });
}); });