From 94373e434c5e52f64a8890bb7ee1fa90dd4f057d Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 13 May 2015 11:26:02 +0200 Subject: [PATCH] Make `tileSize` a field rather than a fn --- src/text-editor-presenter.coffee | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index e5eadbbcd..f5fb1257a 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -67,6 +67,7 @@ class TextEditorPresenter @updateScrollbarDimensions() @updateStartRow() @updateEndRow() + @updateTileSize() @updateFocusedState() if @shouldUpdateFocusedState @updateHeightState() if @shouldUpdateHeightState @@ -300,15 +301,10 @@ class TextEditorPresenter @state.content.backgroundColor = if @model.isMini() then null else @backgroundColor @state.content.placeholderText = if @model.isEmpty() then @model.getPlaceholderText() else null - # REFACTOR: This should be a @field rather than a function. - linesPerTile: -> - linesPerTile = Math.floor(@height / @lineHeight / @tileCount) - Math.max(1, linesPerTile) - tileForRow: (row) -> - row - (row % @linesPerTile()) + row - (row % @tileSize) - getVisibleTileRange: -> + getVisibleTilesRange: -> startTileRow = Math.max(0, @tileForRow(@startRow) - @tileOverdrawMargin) endTileRow = Math.min( @tileForRow(@model.getScreenLineCount()), @@ -321,13 +317,13 @@ class TextEditorPresenter return unless @startRow? and @endRow? and @lineHeight? visibleTiles = {} - for startRow in @getVisibleTileRange() by @linesPerTile() - endRow = Math.min(@model.getScreenLineCount(), startRow + @linesPerTile()) + for startRow in @getVisibleTilesRange() by @tileSize + endRow = Math.min(@model.getScreenLineCount(), startRow + @tileSize) isNewTile = not @state.content.tiles.hasOwnProperty(startRow) tile = @state.content.tiles[startRow] ?= {} tile.top = startRow * @lineHeight - @scrollTop - tile.height = @linesPerTile() * @lineHeight + tile.height = @tileSize * @lineHeight tile.newlyCreated = isNewTile tile.display = "block" @@ -343,7 +339,6 @@ class TextEditorPresenter else delete @state.content.tiles[id] - updateLinesState: (tileState, startRow, endRow) -> tileState.lines ?= {} visibleLineIds = {} @@ -577,6 +572,12 @@ class TextEditorPresenter endRow = startRow + visibleLinesCount @endRow = Math.min(@model.getScreenLineCount(), endRow) + updateTileSize: -> + return unless @height? and @lineHeight? and @tileCount? + + @tileSize = Math.floor(@height / @lineHeight / @tileCount) + @tileSize = Math.max(1, @tileSize) + updateScrollWidth: -> return unless @contentWidth? and @clientWidth?