Fixes issue with preventDefault being called in timeout

This commit is contained in:
Mo Bitar
2019-05-12 11:55:17 -05:00
parent 6c5d01a99d
commit f5e877e055
3 changed files with 18 additions and 12 deletions

View File

@@ -803,10 +803,14 @@ angular.module('app')
this.altKeyObserver = keyboardManager.addKeyObserver({
modifiers: [KeyboardManager.KeyModifierAlt],
onKeyDown: () => {
this.altKeyDown = true;
$timeout(() => {
this.altKeyDown = true;
})
},
onKeyUp: () => {
this.altKeyDown = false;
$timeout(() => {
this.altKeyDown = false;
});
}
})
@@ -815,7 +819,9 @@ angular.module('app')
notElementIds: ["note-text-editor", "note-title-editor"],
modifiers: [KeyboardManager.KeyModifierMeta],
onKeyDown: () => {
this.deleteNote();
$timeout(() => {
this.deleteNote();
});
},
})
@@ -868,8 +874,10 @@ angular.module('app')
editor.selectionStart = editor.selectionEnd = start + 4;
}
this.note.text = editor.value;
this.changesMade({bypassDebouncer: true});
$timeout(() => {
this.note.text = editor.value;
this.changesMade({bypassDebouncer: true});
})
},
})

View File

@@ -573,7 +573,9 @@ angular.module('app')
modifiers: [KeyboardManager.KeyModifierMeta, KeyboardManager.KeyModifierCtrl],
onKeyDown: (event) => {
event.preventDefault();
this.createNewNote();
$timeout(() => {
this.createNewNote();
});
}
})

View File

@@ -1,10 +1,8 @@
class KeyboardManager {
constructor($timeout) {
constructor() {
this.observers = [];
this.$timeout = $timeout;
KeyboardManager.KeyTab = "Tab";
KeyboardManager.KeyBackspace = "Backspace";
@@ -64,9 +62,7 @@ class KeyboardManager {
if(this.eventMatchesKeyAndModifiers(event, observer.key, observer.modifiers)) {
let callback = keyEventType == KeyboardManager.KeyEventDown ? observer.onKeyDown : observer.onKeyUp;
if(callback) {
this.$timeout(() => {
callback(event);
})
callback(event);
}
}
}