From 156569f19e7b5e16d032afa8a0fb856625aa3886 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 18 Feb 2015 11:04:47 -0700 Subject: [PATCH] Add TextEditorPresenter::state.gutter.visible --- spec/text-editor-presenter-spec.coffee | 22 ++++++++++++++++++++++ src/text-editor-presenter.coffee | 8 ++++++++ 2 files changed, 30 insertions(+) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 71f5a2283..143e6f6a5 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -1970,6 +1970,28 @@ describe "TextEditorPresenter", -> editor.undo() expect(lineNumberStateForScreenRow(presenter, 11).foldable).toBe false + describe ".visible", -> + it "is true iff the editor isn't mini, ::isGutterVisible is true on the editor, and 'editor.showLineNumbers' is enabled in config", -> + presenter = buildPresenter() + + expect(editor.isGutterVisible()).toBe true + expect(presenter.state.gutter.visible).toBe true + + expectStateUpdate presenter, -> editor.setMini(true) + expect(presenter.state.gutter.visible).toBe false + + expectStateUpdate presenter, -> editor.setMini(false) + expect(presenter.state.gutter.visible).toBe true + + expectStateUpdate presenter, -> editor.setGutterVisible(false) + expect(presenter.state.gutter.visible).toBe false + + expectStateUpdate presenter, -> editor.setGutterVisible(true) + expect(presenter.state.gutter.visible).toBe true + + expectStateUpdate presenter, -> atom.config.set('editor.showLineNumbers', false) + expect(presenter.state.gutter.visible).toBe false + describe ".height", -> it "tracks the computed content height if ::autoHeight is true so the editor auto-expands vertically", -> presenter = buildPresenter(explicitHeight: null, autoHeight: true) diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 606a8d8bf..b8eee96af 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -64,7 +64,10 @@ class TextEditorPresenter @updateContentState() @updateDecorations() @updateLinesState() + @updateGutterState() @updateLineNumbersState() + @disposables.add @model.onDidChangeGutterVisible => + @updateGutterState() @disposables.add @model.onDidAddDecoration(@didAddDecoration.bind(this)) @disposables.add @model.onDidAddCursor(@didAddCursor.bind(this)) @disposables.add @model.onDidChangeScrollTop(@setScrollTop.bind(this)) @@ -74,6 +77,7 @@ class TextEditorPresenter observeConfig: -> @scrollPastEnd = atom.config.get('editor.scrollPastEnd') + @showLineNumbers = atom.config.get('editor.showLineNumbers') @disposables.add atom.config.onDidChange 'editor.showIndentGuide', scope: @model.getRootScopeDescriptor(), @updateContentState.bind(this) @disposables.add atom.config.onDidChange 'editor.scrollPastEnd', scope: @model.getRootScopeDescriptor(), ({newValue}) => @@ -81,6 +85,9 @@ class TextEditorPresenter @updateScrollHeight() @updateVerticalScrollState() @updateScrollbarsState() + @disposables.add atom.config.onDidChange 'editor.showLineNumbers', scope: @model.getRootScopeDescriptor(), ({newValue}) => + @showLineNumbers = newValue + @updateGutterState() buildState: -> @state = @@ -269,6 +276,7 @@ class TextEditorPresenter @emitter.emit "did-update-state" updateGutterState: -> + @state.gutter.visible = not @model.isMini() and (@model.isGutterVisible() ? true) and @showLineNumbers @state.gutter.maxLineNumberDigits = @model.getLineCount().toString().length @state.gutter.backgroundColor = if @gutterBackgroundColor isnt "rgba(0, 0, 0, 0)" @gutterBackgroundColor