Skip to content
2 changes: 1 addition & 1 deletion src/components/modules/toolbar/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
const shortcut = this.getToolShortcut(tool.name);

if (shortcut !== undefined) {
Shortcuts.remove(this.Editor.UI.nodes.redactor, shortcut);
Shortcuts.remove(document, shortcut);
}

/**
Expand Down
16 changes: 4 additions & 12 deletions src/components/utils/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,16 @@ class Shortcuts {
/**
* All registered shortcuts
*
* @type {Map<Element, Shortcut[]>}
* @type {Map<HTMLElement | Document, Shortcut[]>}
*/
private registeredShortcuts: Map<Element, Shortcut[]> = new Map();
private registeredShortcuts: Map<HTMLElement | Document, Shortcut[]> = new Map();

/**
* Register shortcut
*
* @param shortcut - shortcut options
*/
public add(shortcut: ShortcutData): void {
const foundShortcut = this.findShortcut(shortcut.on, shortcut.name);

if (foundShortcut) {
throw Error(
`Shortcut ${shortcut.name} is already registered for ${shortcut.on}. Please remove it before add a new handler.`
);
}

const newShortcut = new Shortcut({
name: shortcut.name,
on: shortcut.on,
Expand All @@ -75,7 +67,7 @@ class Shortcuts {
* @param element - Element shortcut is set for
* @param name - shortcut name
*/
public remove(element: Element, name: string): void {
public remove(element: HTMLElement | Document, name: string): void {
const shortcut = this.findShortcut(element, name);

if (!shortcut) {
Expand Down Expand Up @@ -104,7 +96,7 @@ class Shortcuts {
* @param shortcut - shortcut name
* @returns {number} index - shortcut index if exist
*/
private findShortcut(element: Element, shortcut: string): Shortcut | void {
private findShortcut(element: HTMLElement | Document, shortcut: string): Shortcut | void {
const shortcuts = this.registeredShortcuts.get(element) || [];

return shortcuts.find(({ name }) => name === shortcut);
Expand Down