Conditionally render the gutter for the showLineNumbers option

Fixes #2707
This commit is contained in:
Ben Ogle
2014-06-23 15:22:16 -07:00
parent 64e2b53baa
commit 7139fd9f98
2 changed files with 19 additions and 3 deletions

View File

@@ -468,6 +468,14 @@ describe "EditorComponent", ->
nextTick()
expect(node.querySelector('.line-numbers').offsetHeight).toBe node.offsetHeight
describe "when the editor.showLineNumbers config is false", ->
it "doesn't render any line numbers", ->
expect(component.refs.gutter).toBeDefined()
atom.config.set("editor.showLineNumbers", false)
expect(component.refs.gutter).not.toBeDefined()
atom.config.set("editor.showLineNumbers", true)
expect(component.refs.gutter).toBeDefined()
describe "fold decorations", ->
describe "rendering fold decorations", ->
it "adds the foldable class to line numbers when the line is foldable", ->

View File

@@ -46,7 +46,7 @@ EditorComponent = React.createClass
scopedCharacterWidthsChangeCount: null
render: ->
{focused, fontSize, lineHeight, fontFamily, showIndentGuide, showInvisibles, visible} = @state
{focused, fontSize, lineHeight, fontFamily, showIndentGuide, showInvisibles, showLineNumbers, visible} = @state
{editor, cursorBlinkPeriod, cursorBlinkResumeDelay} = @props
maxLineNumberDigits = editor.getLineCount().toString().length
invisibles = if showInvisibles then @state.invisibles else {}
@@ -81,13 +81,17 @@ EditorComponent = React.createClass
className += ' is-focused' if focused
className += ' has-selection' if hasSelection
div className: className, style: {fontSize, lineHeight, fontFamily}, tabIndex: -1,
GutterComponent {
gutter = null
if showLineNumbers
gutter = GutterComponent {
ref: 'gutter', onMouseDown: @onGutterMouseDown, onWidthChanged: @onGutterWidthChanged,
lineDecorations, defaultCharWidth, editor, renderedRowRange, maxLineNumberDigits, scrollViewHeight,
scrollTop, scrollHeight, lineHeightInPixels, @pendingChanges, mouseWheelScreenRow
}
div className: className, style: {fontSize, lineHeight, fontFamily}, tabIndex: -1,
gutter
div ref: 'scrollView', className: 'scroll-view', onMouseDown: @onMouseDown,
InputComponent
ref: 'input'
@@ -450,6 +454,7 @@ EditorComponent = React.createClass
@subscribe atom.config.observe 'editor.showIndentGuide', @setShowIndentGuide
@subscribe atom.config.observe 'editor.invisibles', @setInvisibles
@subscribe atom.config.observe 'editor.showInvisibles', @setShowInvisibles
@subscribe atom.config.observe 'editor.showLineNumbers', @setShowLineNumbers
@subscribe atom.config.observe 'editor.scrollSensitivity', @setScrollSensitivity
onFocus: ->
@@ -835,6 +840,9 @@ EditorComponent = React.createClass
setShowInvisibles: (showInvisibles) ->
@setState({showInvisibles})
setShowLineNumbers: (showLineNumbers) ->
@setState({showLineNumbers})
setScrollSensitivity: (scrollSensitivity) ->
if scrollSensitivity = parseInt(scrollSensitivity)
@scrollSensitivity = Math.abs(scrollSensitivity) / 100