From 590391a0ce17bb47b8939eaee2f4ff607b728e4d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 21 Jan 2015 09:38:54 -0700 Subject: [PATCH] =?UTF-8?q?Update=20.content.indentGuidesVisible=20when=20?= =?UTF-8?q?editor=E2=80=99s=20grammar=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/text-editor-presenter-spec.coffee | 16 ++++++++++++++++ src/text-editor-presenter.coffee | 7 ++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 58706073b..47919bc53 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -87,6 +87,22 @@ describe "TextEditorPresenter", -> atom.config.set('editor.showIndentGuide', false) expect(presenter.state.content.indentGuidesVisible).toBe false + describe "when the editor's grammar changes", -> + it "updates .indentGuidesVisible based on the grammar's root scope", -> + atom.config.set('editor.showIndentGuide', true, scopeSelector: ".source.js") + + presenter = new TextEditorPresenter(model: editor, clientHeight: 25, clientWidth: 50, scrollTop: 0, baseCharacterWidth: 10, lineHeight: 10, lineOverdrawMargin: 0) + expect(presenter.state.content.indentGuidesVisible).toBe false + + waitsForPromise -> atom.packages.activatePackage('language-javascript') + + runs -> + editor.setGrammar(atom.grammars.selectGrammar('.js')) + expect(presenter.state.content.indentGuidesVisible).toBe true + + editor.setGrammar(atom.grammars.selectGrammar('.txt')) + expect(presenter.state.content.indentGuidesVisible).toBe false + describe "::state.content.lines", -> describe "on initialization", -> it "contains the lines that are visible on screen, plus the overdraw margin", -> diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 9a3353a3a..a47ce563c 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -18,9 +18,10 @@ class TextEditorPresenter @disposables.add @model.onDidChangeSoftWrapped => @updateContentState() @updateLinesState() + @disposables.add @model.onDidChangeGrammar(@updateContentState.bind(this)) observeConfig: -> - @disposables.add atom.config.onDidChange 'editor.showIndentGuide', @updateContentState.bind(this) + @disposables.add atom.config.onDidChange 'editor.showIndentGuide', scope: @model.getRootScopeDescriptor(), @updateContentState.bind(this) buildState: -> @state = {} @@ -30,7 +31,7 @@ class TextEditorPresenter buildContentState: -> @state.content = scrollWidth: @computeScrollWidth() - indentGuidesVisible: atom.config.get('editor.showIndentGuide') + indentGuidesVisible: atom.config.get('editor.showIndentGuide', scope: @model.getRootScopeDescriptor()) buildLinesState: -> @state.content.lines = {} @@ -38,7 +39,7 @@ class TextEditorPresenter updateContentState: -> @state.content.scrollWidth = @computeScrollWidth() - @state.content.indentGuidesVisible = atom.config.get('editor.showIndentGuide') + @state.content.indentGuidesVisible = atom.config.get('editor.showIndentGuide', scope: @model.getRootScopeDescriptor()) updateLinesState: -> visibleLineIds = {}