Add TextEditorElement::getMaxScrollTop

This commit is contained in:
Antonio Scandurra
2015-10-20 08:36:27 +02:00
parent ec9d1231aa
commit 40e3b08a8c
4 changed files with 37 additions and 0 deletions

View File

@@ -236,6 +236,27 @@ describe "TextEditorElement", ->
jasmine.attachToDOM(element)
expect(element.getDefaultCharacterWidth()).toBeGreaterThan(0)
describe "::getMaxScrollTop", ->
it "returns the maximum scroll top that can be applied to the element", ->
editor = atom.workspace.buildTextEditor()
editor.setText('1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16')
element = atom.views.getView(editor)
element.style.lineHeight = "10px"
element.style.width = "200px"
expect(element.getMaxScrollTop()).toBe(0)
jasmine.attachToDOM(element)
element.setHeight(100)
expect(element.getMaxScrollTop()).toBe(60)
element.setHeight(120)
expect(element.getMaxScrollTop()).toBe(40)
element.setHeight(200)
expect(element.getMaxScrollTop()).toBe(0)
describe "on TextEditor::setMini", ->
it "changes the element's 'mini' attribute", ->
element = new TextEditorElement

View File

@@ -421,6 +421,9 @@ class TextEditorComponent
getScrollWidth: ->
@presenter.getScrollWidth()
getMaxScrollTop: ->
@presenter.getMaxScrollTop()
getVerticalScrollbarWidth: ->
@presenter.getVerticalScrollbarWidth()

View File

@@ -210,6 +210,12 @@ class TextEditorElement extends HTMLElement
getDefaultCharacterWidth: ->
@getModel().getDefaultCharWidth()
# Extended: Get the maximum scroll top that can be applied to this element.
#
# Returns a {Number} of pixels.
getMaxScrollTop: ->
@component?.getMaxScrollTop()
# Extended: Converts a buffer position to a pixel position.
#
# * `bufferPosition` An object that represents a buffer position. It can be either

View File

@@ -982,6 +982,13 @@ class TextEditorPresenter
getScrollWidth: ->
@scrollWidth
getMaxScrollTop: ->
scrollHeight = @getScrollHeight()
clientHeight = @getClientHeight()
return 0 unless scrollHeight? and clientHeight?
scrollHeight - clientHeight
setHorizontalScrollbarHeight: (horizontalScrollbarHeight) ->
unless @measuredHorizontalScrollbarHeight is horizontalScrollbarHeight
oldHorizontalScrollbarHeight = @measuredHorizontalScrollbarHeight