Fix Console bug caused by rapidly opening and closing the History tab. (#38950) (#39012)

This commit is contained in:
CJ Cenizal 2019-06-14 13:58:13 -07:00 committed by GitHub
parent f40fa383b2
commit 2b25f3b081
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -81,7 +81,7 @@ export default function SenseEditor($el) {
// dirty check for tokenizer state, uses a lot less cycles
// than listening for tokenizerUpdate
const onceDoneTokenizing = function (func, cancelAlreadyScheduledCalls) {
const onceDoneTokenizing = function (callback, cancelAlreadyScheduledCalls) {
const session = editor.getSession();
let timer = false;
const checkInterval = 25;
@ -95,11 +95,15 @@ export default function SenseEditor($el) {
}
setTimeout(function check() {
if (session.bgTokenizer.running) {
timer = setTimeout(check, checkInterval);
}
else {
func.apply(self, args);
// If the bgTokenizer doesn't exist, we can assume that the underlying editor has been
// torn down, e.g. by closing the History tab, and we don't need to do anything further.
if (session.bgTokenizer) {
// Wait until the bgTokenizer is done running before executing the callback.
if (session.bgTokenizer.running) {
timer = setTimeout(check, checkInterval);
} else {
callback.apply(self, args);
}
}
});
};