From 2c5888e25a0a06c8215ff56de8cb3227f529482c Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 21 Jan 2015 16:47:03 -0700 Subject: [PATCH] Add ::state.content.scrollHeight to TextEditorPresenter --- spec/text-editor-presenter-spec.coffee | 15 +++++++++++++++ src/text-editor-presenter.coffee | 12 ++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index a0023bce7..3dffc19e3 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -67,6 +67,21 @@ describe "TextEditorPresenter", -> editor.setSoftWrapped(false) expect(presenter.state.content.scrollWidth).toBe 10 * editor.getMaxScreenLineLength() + 1 + describe ".scrollHeight", -> + it "is initialized based on the lineHeight and the number of lines", -> + presenter = new TextEditorPresenter(model: editor, scrollTop: 0, lineHeight: 10, lineOverdrawMargin: 1) + expect(presenter.state.content.scrollHeight).toBe editor.getScreenLineCount() * 10 + + it "updates when the ::lineHeight changes", -> + presenter = new TextEditorPresenter(model: editor, scrollTop: 0, lineHeight: 10, lineOverdrawMargin: 1) + presenter.setLineHeight(20) + expect(presenter.state.content.scrollHeight).toBe editor.getScreenLineCount() * 20 + + it "updates when the line count changes", -> + presenter = new TextEditorPresenter(model: editor, scrollTop: 0, lineHeight: 10, lineOverdrawMargin: 1) + editor.getBuffer().append("\n\n\n") + expect(presenter.state.content.scrollHeight).toBe editor.getScreenLineCount() * 10 + describe ".indentGuidesVisible", -> it "is initialized based on the editor.showIndentGuide config setting", -> presenter = new TextEditorPresenter(model: editor) diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 33975e299..a46c4ac45 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -14,7 +14,7 @@ class TextEditorPresenter @disposables.dispose() observeModel: -> - @disposables.add @model.onDidChange(@updateLinesState.bind(this)) + @disposables.add @model.onDidChange(@updateState.bind(this)) @disposables.add @model.onDidChangeSoftWrapped(@updateState.bind(this)) @disposables.add @model.onDidChangeGrammar(@updateContentState.bind(this)) @disposables.add @model.onDidAddDecoration(@didAddDecoration.bind(this)) @@ -30,9 +30,8 @@ class TextEditorPresenter @buildLinesState() buildContentState: -> - @state.content = - scrollWidth: @computeScrollWidth() - indentGuidesVisible: atom.config.get('editor.showIndentGuide', scope: @model.getRootScopeDescriptor()) + @state.content = {} + @updateContentState() buildLinesState: -> @state.content.lines = {} @@ -44,6 +43,7 @@ class TextEditorPresenter updateContentState: -> @state.content.scrollWidth = @computeScrollWidth() + @state.content.scrollHeight = @computeScrollHeight() @state.content.indentGuidesVisible = atom.config.get('editor.showIndentGuide', scope: @model.getRootScopeDescriptor()) updateLinesState: -> @@ -98,6 +98,9 @@ class TextEditorPresenter contentWidth += 1 unless @model.isSoftWrapped() # account for cursor width Math.max(contentWidth, @getClientWidth()) + computeScrollHeight: -> + @getLineHeight() * @model.getScreenLineCount() + lineDecorationClassesForRow: (row) -> return null if @model.isMini() @@ -136,6 +139,7 @@ class TextEditorPresenter getClientWidth: -> @clientWidth setLineHeight: (@lineHeight) -> + @updateContentState() @updateLinesState() getLineHeight: -> @lineHeight