mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-05 17:40:26 +00:00
Merge pull request #70 from GuAlSe/fix
Override useless browser hotkeys if editor is active
This commit is contained in:
commit
94d2221250
@ -88,10 +88,11 @@ class Shortcut {
|
|||||||
|
|
||||||
// Advanced stuff.
|
// Advanced stuff.
|
||||||
class ShortcutHandler {
|
class ShortcutHandler {
|
||||||
constructor(element, filter = () => true) {
|
constructor(element, override, filter = () => true) {
|
||||||
this.element = element;
|
this.element = element;
|
||||||
this.map = {};
|
this.map = {};
|
||||||
this.active = this.map;
|
this.active = this.map;
|
||||||
|
this.override = override;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
this.timeout = null;
|
this.timeout = null;
|
||||||
|
|
||||||
@ -166,6 +167,9 @@ class Shortcut {
|
|||||||
this.active = this.active[shortcut];
|
this.active = this.active[shortcut];
|
||||||
if (this.active.action) {
|
if (this.active.action) {
|
||||||
this.active.action(event);
|
this.active.action(event);
|
||||||
|
if (this.override) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
this.resetActive();
|
this.resetActive();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -268,7 +272,7 @@ class Shortcut {
|
|||||||
closeShortcutsReference();
|
closeShortcutsReference();
|
||||||
};
|
};
|
||||||
|
|
||||||
let dialogShortcuts = new ShortcutHandler(dialog, notTextField);
|
let dialogShortcuts = new ShortcutHandler(dialog, true, notTextField);
|
||||||
|
|
||||||
dialogShortcuts.add('Escape', handleClose);
|
dialogShortcuts.add('Escape', handleClose);
|
||||||
closeButton.addEventListener('click', handleClose);
|
closeButton.addEventListener('click', handleClose);
|
||||||
@ -298,7 +302,7 @@ class Shortcut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
let globalShortcuts = new ShortcutHandler(document, notTextField);
|
let globalShortcuts = new ShortcutHandler(document, false, notTextField);
|
||||||
|
|
||||||
// Global shortcuts
|
// Global shortcuts
|
||||||
|
|
||||||
@ -343,7 +347,7 @@ class Shortcut {
|
|||||||
|
|
||||||
// * Editor shortcuts
|
// * Editor shortcuts
|
||||||
if (typeof editTextarea !== 'undefined') {
|
if (typeof editTextarea !== 'undefined') {
|
||||||
let editorShortcuts = new ShortcutHandler(editTextarea);
|
let editorShortcuts = new ShortcutHandler(editTextarea, true);
|
||||||
let bindElement = bindElementFactory(editorShortcuts);
|
let bindElement = bindElementFactory(editorShortcuts);
|
||||||
|
|
||||||
let shortcuts = [
|
let shortcuts = [
|
||||||
|
Loading…
Reference in New Issue
Block a user