mirror of
https://github.com/atom/atom.git
synced 2026-02-10 06:35:00 -05:00
Associate gutters with their elements and support showing/hiding gutters
This commit is contained in:
committed by
Antonio Scandurra
parent
16694a2166
commit
d8b22fb3bd
@@ -8,6 +8,9 @@ class GutterContainer
|
||||
@textEditor = textEditor
|
||||
@emitter = new Emitter
|
||||
|
||||
scheduleComponentUpdate: ->
|
||||
@textEditor.scheduleComponentUpdate()
|
||||
|
||||
destroy: ->
|
||||
# Create a copy, because `Gutter::destroy` removes the gutter from
|
||||
# GutterContainer's @gutters.
|
||||
|
||||
@@ -70,12 +70,14 @@ class Gutter
|
||||
hide: ->
|
||||
if @visible
|
||||
@visible = false
|
||||
@gutterContainer.scheduleComponentUpdate()
|
||||
@emitter.emit 'did-change-visible', this
|
||||
|
||||
# Essential: Show the gutter.
|
||||
show: ->
|
||||
if not @visible
|
||||
@visible = true
|
||||
@gutterContainer.scheduleComponentUpdate()
|
||||
@emitter.emit 'did-change-visible', this
|
||||
|
||||
# Essential: Determine whether the gutter is visible.
|
||||
|
||||
@@ -242,7 +242,11 @@ class TextEditorComponent {
|
||||
if (gutter.name === 'line-number') {
|
||||
return this.renderLineNumberGutter()
|
||||
} else {
|
||||
return this.renderCustomGutter(gutter.name)
|
||||
return $(CustomGutterComponent, {
|
||||
key: gutter,
|
||||
gutter: gutter,
|
||||
height: this.getScrollHeight()
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@@ -323,19 +327,6 @@ class TextEditorComponent {
|
||||
}
|
||||
}
|
||||
|
||||
renderCustomGutter (gutterName) {
|
||||
return $.div(
|
||||
{
|
||||
className: 'gutter',
|
||||
attributes: {'gutter-name': gutterName}
|
||||
},
|
||||
$.div({
|
||||
className: 'custom-decorations',
|
||||
style: {height: this.getScrollHeight() + 'px'}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
renderScrollContainer () {
|
||||
const style = {
|
||||
position: 'absolute',
|
||||
@@ -2106,6 +2097,35 @@ class LineNumberGutterComponent {
|
||||
}
|
||||
}
|
||||
|
||||
class CustomGutterComponent {
|
||||
constructor (props) {
|
||||
this.props = props
|
||||
etch.initialize(this)
|
||||
this.props.gutter.element = this.element
|
||||
}
|
||||
|
||||
update (props) {
|
||||
this.props = props
|
||||
etch.updateSync(this)
|
||||
}
|
||||
|
||||
render () {
|
||||
return $.div(
|
||||
{
|
||||
className: 'gutter',
|
||||
attributes: {'gutter-name': this.props.gutter.name},
|
||||
style: {
|
||||
display: this.props.gutter.isVisible() ? '' : 'none'
|
||||
}
|
||||
},
|
||||
$.div({
|
||||
className: 'custom-decorations',
|
||||
style: {height: this.props.height + 'px'}
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class LinesTileComponent {
|
||||
constructor (props) {
|
||||
this.props = props
|
||||
|
||||
@@ -392,6 +392,9 @@ class TextEditor extends Model
|
||||
else
|
||||
Promise.resolve()
|
||||
|
||||
scheduleComponentUpdate: ->
|
||||
@component?.scheduleUpdate()
|
||||
|
||||
serialize: ->
|
||||
tokenizedBufferState = @tokenizedBuffer.serialize()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user