From 71a27de7ac196dae28afe434a1bfb08a34192002 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 27 Jan 2015 10:27:07 -0700 Subject: [PATCH] Add TextEditorPresenter::state.content.backgroundColor --- spec/text-editor-presenter-spec.coffee | 20 ++++++++++++++++++++ src/text-editor-presenter.coffee | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index e0da60ec8..463e01e1c 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -153,6 +153,26 @@ describe "TextEditorPresenter", -> expectStateUpdate presenter, -> editor.setGrammar(atom.grammars.selectGrammar('.txt')) expect(presenter.state.content.indentGuidesVisible).toBe false + describe ".backgroundColor", -> + it "is assigned to ::backgroundColor unless the editor is mini", -> + presenter = new TextEditorPresenter(model: editor, backgroundColor: 'rgba(255, 0, 0, 0)') + expect(presenter.state.content.backgroundColor).toBe 'rgba(255, 0, 0, 0)' + editor.setMini(true) + presenter = new TextEditorPresenter(model: editor, backgroundColor: 'rgba(255, 0, 0, 0)') + expect(presenter.state.content.backgroundColor).toBeNull() + + it "updates when ::backgroundColor changes", -> + presenter = new TextEditorPresenter(model: editor, backgroundColor: 'rgba(255, 0, 0, 0)') + expect(presenter.state.content.backgroundColor).toBe 'rgba(255, 0, 0, 0)' + expectStateUpdate presenter, -> presenter.setBackgroundColor('rgba(0, 0, 255, 0)') + expect(presenter.state.content.backgroundColor).toBe 'rgba(0, 0, 255, 0)' + + it "updates when ::mini changes", -> + presenter = new TextEditorPresenter(model: editor, backgroundColor: 'rgba(255, 0, 0, 0)') + expect(presenter.state.content.backgroundColor).toBe 'rgba(255, 0, 0, 0)' + expectStateUpdate presenter, -> editor.setMini(true) + expect(presenter.state.content.backgroundColor).toBeNull() + describe ".lines", -> lineStateForScreenRow = (presenter, screenRow) -> presenter.state.content.lines[presenter.model.tokenizedLineForScreenRow(screenRow).id] diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 6315ce67a..943e6084a 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -7,7 +7,7 @@ class TextEditorPresenter toggleCursorBlinkHandle: null startBlinkingCursorsAfterDelay: null - constructor: ({@model, @clientHeight, @clientWidth, @scrollTop, @scrollLeft, @lineHeight, @baseCharacterWidth, @lineOverdrawMargin, @cursorBlinkPeriod, @cursorBlinkResumeDelay}) -> + constructor: ({@model, @clientHeight, @clientWidth, @scrollTop, @scrollLeft, @lineHeight, @baseCharacterWidth, @lineOverdrawMargin, @cursorBlinkPeriod, @cursorBlinkResumeDelay, @backgroundColor}) -> @disposables = new CompositeDisposable @emitter = new Emitter @charWidthsByScope = {} @@ -27,6 +27,7 @@ class TextEditorPresenter @disposables.add @model.onDidChangeSoftWrapped(@updateState.bind(this)) @disposables.add @model.onDidChangeGrammar(@updateContentState.bind(this)) @disposables.add @model.onDidChangeMini => + @updateContentState() @updateLinesState() @updateLineNumbersState() @disposables.add @model.onDidAddDecoration(@didAddDecoration.bind(this)) @@ -68,6 +69,7 @@ class TextEditorPresenter @state.content.scrollWidth = @computeScrollWidth() @state.content.scrollLeft = @getScrollLeft() @state.content.indentGuidesVisible = atom.config.get('editor.showIndentGuide', scope: @model.getRootScopeDescriptor()) + @state.content.backgroundColor = if @model.isMini() then null else @getBackgroundColor() @emitter.emit 'did-update-state' updateLinesState: -> @@ -348,6 +350,11 @@ class TextEditorPresenter getClientWidth: -> @clientWidth + setBackgroundColor: (@backgroundColor) -> + @updateContentState() + + getBackgroundColor: -> @backgroundColor + setLineHeight: (@lineHeight) -> @updateVerticalScrollState() @updateLinesState()