Skip to content

Commit

Permalink
perf: remove multiple event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Nov 30, 2018
1 parent bcca64a commit 0c22a10
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ function checkForInConsoleTabSwitch(editor: TextEditor): boolean {

// toggle statusBarItem when document changes
function toggleStatusBarItem(editor: TextEditor | undefined): void {
if (!statusBarItem) {
return;
}

if (editor !== undefined) {
if (checkForInConsoleTabSwitch(editor)) { return; }

// hide statusBarItem if document changes and doesn't match supported languages
const score = languages.match(supportedLanguages, editor.document);
score ? statusBarItem.show() : statusBarItem.hide();
} else {
statusBarItem.hide();
}
}

Expand Down Expand Up @@ -113,14 +119,7 @@ export function registerErrorHandlerDisposables(): Disposable[] {
return [
// Keep track whether to show/hide the statusbar
window.onDidChangeActiveTextEditor((editor: TextEditor | undefined) => {
if (statusBarItem !== undefined) {
toggleStatusBarItem(editor);
}
}),
window.onDidChangeActiveTextEditor((editor: TextEditor | undefined) => {
if (editor === undefined) {
statusBarItem.hide();
}
toggleStatusBarItem(editor);
})
];
}

0 comments on commit 0c22a10

Please sign in to comment.