mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
[Gutter] Factor out method to set common gutter component properties
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
16
src/gutter-component-helpers.coffee
Normal file
16
src/gutter-component-helpers.coffee
Normal 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
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user