Skip to content

Commit

Permalink
[Gutter] Factor out method to set common gutter component properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Jess Lin committed Apr 22, 2015
1 parent 7f1b058 commit e2e7373
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
12 changes: 3 additions & 9 deletions src/custom-gutter-component.coffee
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions src/gutter-component-helpers.coffee
Original file line number Diff line number Diff line change
@@ -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
13 changes: 2 additions & 11 deletions src/line-number-gutter-component.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
_ = require 'underscore-plus'
{setDimensionsAndBackground} = require './gutter-component-helpers'

WrapperDiv = document.createElement('div')

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e2e7373

Please sign in to comment.