From e6cac10a238c8b6ed095332133bb5a6d12bcb4ad Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 5 Oct 2016 12:03:53 -0700 Subject: [PATCH] Always return Disposable from maintain{Config,Grammar} --- spec/text-editor-registry-spec.js | 40 +++++++++++++++++++++++++++++++ src/text-editor-registry.js | 6 +++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/spec/text-editor-registry-spec.js b/spec/text-editor-registry-spec.js index 812676305..05c9548b7 100644 --- a/spec/text-editor-registry-spec.js +++ b/spec/text-editor-registry-spec.js @@ -125,6 +125,25 @@ describe('TextEditorRegistry', function () { expect(editor.getGrammar().name).toBe('Null Grammar') expect(retainedEditorCount(registry)).toBe(0) }) + + describe('when called twice with a given editor', function () { + it('does nothing the second time', async function () { + await atom.packages.activatePackage('language-javascript') + const disposable1 = registry.maintainGrammar(editor) + const disposable2 = registry.maintainGrammar(editor) + + editor.getBuffer().setPath('test.js') + expect(editor.getGrammar().name).toBe('JavaScript') + + disposable2.dispose() + editor.getBuffer().setPath('test.txt') + expect(editor.getGrammar().name).toBe('Null Grammar') + + disposable1.dispose() + editor.getBuffer().setPath('test.js') + expect(editor.getGrammar().name).toBe('Null Grammar') + }) + }) }) describe('.setGrammarOverride', function () { @@ -625,6 +644,27 @@ describe('TextEditorRegistry', function () { expect(delegate.getNonWordCharacters(['e.f', 'g.h'])).toBe('(){}[]') expect(delegate.getNonWordCharacters(['i.j'])).toBe('()') }) + + describe('when called twice with a given editor', function () { + it('does nothing the second time', async function () { + editor.update({scrollSensitivity: 50}) + + const disposable1 = registry.maintainConfig(editor) + const disposable2 = registry.maintainConfig(editor) + await initialPackageActivation + + atom.config.set('editor.scrollSensitivity', 60) + expect(editor.getScrollSensitivity()).toBe(60) + + disposable2.dispose() + atom.config.set('editor.scrollSensitivity', 70) + expect(editor.getScrollSensitivity()).toBe(70) + + disposable1.dispose() + atom.config.set('editor.scrollSensitivity', 80) + expect(editor.getScrollSensitivity()).toBe(70) + }) + }) }) describe('serialization', function () { diff --git a/src/text-editor-registry.js b/src/text-editor-registry.js index bda3712e7..9868df2d5 100644 --- a/src/text-editor-registry.js +++ b/src/text-editor-registry.js @@ -157,7 +157,7 @@ export default class TextEditorRegistry { // configuration. maintainConfig (editor) { if (this.editorsWithMaintainedConfig.has(editor)) { - return + return new Disposable(noop) } this.editorsWithMaintainedConfig.add(editor) @@ -202,7 +202,7 @@ export default class TextEditorRegistry { // grammar. maintainGrammar (editor) { if (this.editorsWithMaintainedGrammar.has(editor)) { - return + return new Disposable(noop) } this.editorsWithMaintainedGrammar.add(editor) @@ -391,6 +391,8 @@ function shouldEditorUseSoftTabs (editor, tabType, softTabs) { } } +function noop () {} + class ScopedSettingsDelegate { constructor (config) { this.config = config