From 3d5383ceaf94f301937ca04ef71e132577cd2d2a Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 29 Aug 2017 17:59:45 +0300 Subject: [PATCH] debounce and subscribe updateLinter --- edit/edit.js | 3 --- edit/lint.js | 15 +++++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/edit/edit.js b/edit/edit.js index b6ebaa74..927d2ca1 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -371,9 +371,6 @@ function acmeEventListener(event) { } option = 'highlightSelectionMatches'; break; - case 'linter': - debounce(updateLinter); - break; } CodeMirror.setOption(option, value); } diff --git a/edit/lint.js b/edit/lint.js index 5bb30033..9930cae5 100644 --- a/edit/lint.js +++ b/edit/lint.js @@ -93,7 +93,7 @@ var linterConfig = { if (area === 'sync') { for (const name of ['editorCSSLintConfig', 'editorStylelintConfig']) { if (name in changes && changes[name].newValue !== changes[name].oldValue) { - this.loadAll().then(() => debounce(updateLinter)); + this.loadAll().then(updateLinter); break; } } @@ -132,9 +132,16 @@ function initLint() { linterConfig.loadAll(); linterConfig.watchStorage(); + prefs.subscribe(updateLinter, ['editor.linter']); + updateLinter(); } -function updateLinter(linter = prefs.get('editor.linter')) { +function updateLinter({immediately} = {}) { + if (!immediately) { + debounce(updateLinter, 0, {immediately: true}); + return; + } + const linter = prefs.get('editor.linter'); const GUTTERS_CLASS = 'CodeMirror-lint-markers'; function updateEditors() { @@ -147,7 +154,7 @@ function updateLinter(linter = prefs.get('editor.linter')) { updateGutters(cm, guttersOption); } cm.refresh(); - updateLintReport(cm, 200); + updateLintReport(cm); }); } @@ -408,7 +415,7 @@ function setupLinterSettingsEvents(popup) { } linterConfig.save(json); linterConfig.showSavedMessage(); - debounce(updateLinter); + updateLinter(); } else { showLinterErrorMessage(linter, t('linterJSONError')); }