[Gutter] Factor out method to set common gutter component properties

This commit is contained in:
Jess Lin
2015-03-30 15:28:41 -07:00
parent 7f1b0588f9
commit e2e737369a
3 changed files with 21 additions and 20 deletions

View File

@@ -1,3 +1,5 @@
{setDimensionsAndBackground} = require './gutter-component-helpers'
# This class represents a gutter other than the 'line-numbers' gutter.
# The contents of this gutter may be specified by Decorations.
@@ -33,15 +35,7 @@ class CustomGutterComponent
decorationState = state.gutters.customDecorations[@getName()]
@oldState ?= {}
# TODO (jessicalin) Factor this out (also in LineNumberGutterComponent).
# Also, set backgroundColor?
if gutterProps.scrollHeight isnt @oldState.scrollHeight
@decorationsNode.style.height = gutterProps.scrollHeight + 'px'
@oldState.scrollHeight = gutterProps.scrollHeight
if gutterProps.scrollTop isnt @oldState.scrollTop
@decorationsNode.style['-webkit-transform'] = "translate3d(0px, #{-gutterProps.scrollTop}px, 0px)"
@oldState.scrollTop = gutterProps.scrollTop
setDimensionsAndBackground(@oldState, gutterProps, @decorationsNode)
return if !decorationState

View File

@@ -0,0 +1,16 @@
# Helper methods shared among GutterComponent classes.
module.exports =
# Sets scrollHeight, scrollTop, and backgroundColor on the given domNode.
setDimensionsAndBackground: (oldState, newState, domNode) ->
if newState.scrollHeight isnt oldState.scrollHeight
domNode.style.height = newState.scrollHeight + 'px'
oldState.scrollHeight = newState.scrollHeight
if newState.scrollTop isnt oldState.scrollTop
domNode.style['-webkit-transform'] = "translate3d(0px, #{-newState.scrollTop}px, 0px)"
oldState.scrollTop = newState.scrollTop
if newState.backgroundColor isnt oldState.backgroundColor
domNode.style.backgroundColor = newState.backgroundColor
oldState.backgroundColor = newState.backgroundColor

View File

@@ -1,4 +1,5 @@
_ = require 'underscore-plus'
{setDimensionsAndBackground} = require './gutter-component-helpers'
WrapperDiv = document.createElement('div')
@@ -30,17 +31,7 @@ class LineNumberGutterComponent
@appendDummyLineNumber() unless @dummyLineNumberNode?
if @newState.scrollHeight isnt @oldState.scrollHeight
@lineNumbersNode.style.height = @newState.scrollHeight + 'px'
@oldState.scrollHeight = @newState.scrollHeight
if @newState.scrollTop isnt @oldState.scrollTop
@lineNumbersNode.style['-webkit-transform'] = "translate3d(0px, #{-@newState.scrollTop}px, 0px)"
@oldState.scrollTop = @newState.scrollTop
if @newState.backgroundColor isnt @oldState.backgroundColor
@lineNumbersNode.style.backgroundColor = @newState.backgroundColor
@oldState.backgroundColor = @newState.backgroundColor
setDimensionsAndBackground(@oldState, @newState, @lineNumbersNode)
if @newState.maxLineNumberDigits isnt @oldState.maxLineNumberDigits
@updateDummyLineNumber()