Add TextEditor::set/isGutterVisible

Controls gutter visibility on individual editors.

Signed-off-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Nathan Sobo 2015-01-12 11:10:58 -07:00
parent 6ef8c21977
commit f00b0b7f7a
3 changed files with 37 additions and 13 deletions

View File

@ -552,14 +552,29 @@ describe "TextEditorComponent", ->
nextAnimationFrame()
expect(lineNumbersNode.style.backgroundColor).toBe 'rgb(255, 0, 0)'
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()
expect(component.lineNumberNodeForScreenRow(3)).toBeDefined()
it "hides or shows the gutter based on the '::isGutterVisible' property on the model and the global 'editor.showLineNumbers' config setting", ->
expect(component.refs.gutter?).toBe true
editor.setGutterVisible(false)
nextAnimationFrame()
expect(component.refs.gutter?).toBe false
atom.config.set("editor.showLineNumbers", false)
nextAnimationFrame()
expect(component.refs.gutter?).toBe false
editor.setGutterVisible(true)
nextAnimationFrame()
expect(component.refs.gutter?).toBe false
atom.config.set("editor.showLineNumbers", true)
nextAnimationFrame()
expect(component.refs.gutter?).toBe true
expect(component.lineNumberNodeForScreenRow(3)?).toBe true
describe "fold decorations", ->
describe "rendering fold decorations", ->

View File

@ -160,7 +160,7 @@ TextEditorComponent = React.createClass
Math.max(1, Math.ceil(editor.getHeight() / editor.getLineHeightInPixels()))
shouldRenderGutter: ->
not @props.mini and @state.showLineNumbers
not @props.mini and @props.editor.isGutterVisible() and atom.config.get('editor.showLineNumbers')
getInitialState: -> {}
@ -463,7 +463,8 @@ TextEditorComponent = React.createClass
scopeDescriptor = editor.getRootScopeDescriptor()
subscriptions.add atom.config.observe 'editor.showIndentGuide', scope: scopeDescriptor, @setShowIndentGuide
subscriptions.add atom.config.observe 'editor.showLineNumbers', scope: scopeDescriptor, @setShowLineNumbers
subscriptions.add atom.config.onDidChange 'editor.showLineNumbers', scope: scopeDescriptor, @requestUpdate
subscriptions.add editor.onDidChangeGutterVisible @requestUpdate
subscriptions.add atom.config.observe 'editor.scrollSensitivity', scope: scopeDescriptor, @setScrollSensitivity
focused: ->
@ -1010,9 +1011,6 @@ TextEditorComponent = React.createClass
setShowInvisibles: (showInvisibles) ->
atom.config.set('editor.showInvisibles', showInvisibles)
setShowLineNumbers: (showLineNumbers) ->
@setState({showLineNumbers})
setScrollSensitivity: (scrollSensitivity) ->
if scrollSensitivity = parseInt(scrollSensitivity)
@scrollSensitivity = Math.abs(scrollSensitivity) / 100

View File

@ -536,6 +536,17 @@ class TextEditor extends Model
isMini: -> @mini
setGutterVisible: (gutterVisible) ->
unless gutterVisible is @gutterVisible
@gutterVisible = gutterVisible
@emitter.emit 'did-change-gutter-visible', @gutterVisible
@gutterVisible
isGutterVisible: -> @gutterVisible ? true
onDidChangeGutterVisible: (callback) ->
@emitter.on 'did-change-gutter-visible', callback
# Set the number of characters that can be displayed horizontally in the
# editor.
#