Skip to content

Commit af96ec2

Browse files
committed
Update blame view upon save
Fixes #29. Test plan: First test editing when view is open: * Open blame * Add some newlines * Save file * See blame view update Now test it updates upon second display: * Open blame * Close blame * Add some newlines * Save file * Open blame again * See it update
1 parent 1e14f49 commit af96ec2

File tree

3 files changed

+40
-26
lines changed

3 files changed

+40
-26
lines changed

lib/controllers/blameViewController.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ function toggleBlame(projectBlamer) {
3636
editorView.blameView = React.renderComponent(new BlameListView({
3737
projectBlamer: projectBlamer,
3838
remoteRevision: remoteRevision,
39-
filePath: filePath,
40-
lineCount: editor.getLineCount(),
41-
scrollbar: editorView.find('.vertical-scrollbar')
39+
editorView: editorView
4240
}), mountPoint[0]);
4341
} else {
4442
editorView.blameView.toggle();

lib/views/blame-line-view.coffee

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,4 @@ BlameLineComponent = React.createClass
4747
componentWillUnmount: ->
4848
$(@getDOMNode()).tooltip "destroy"
4949

50-
shouldComponentUpdate: ->
51-
false
52-
5350
module.exports = {BlameLineComponent, renderLoading}

lib/views/blame-list-view.coffee

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{React, Reactionary, $} = require 'atom'
2-
{div, span, a} = Reactionary
2+
{div} = Reactionary
33
RP = React.PropTypes
44
_ = require 'underscore'
55
{BlameLineComponent, renderLoading} = require './blame-line-view'
@@ -9,12 +9,11 @@ BlameListLinesComponent = React.createClass
99
propTypes:
1010
annotations: RP.arrayOf(RP.object)
1111
loading: RP.bool.isRequired
12-
filePath: RP.string.isRequired
13-
lineCount: RP.number.isRequired
12+
initialLineCount: RP.number.isRequired
1413
remoteRevision: RP.object.isRequired
1514

1615
renderLoading: ->
17-
lines = [0...@props.lineCount].map renderLoading
16+
lines = [0...@props.initialLineCount].map renderLoading
1817
div null, lines
1918

2019
# makes background color alternate by commit
@@ -57,20 +56,25 @@ BlameListView = React.createClass
5756
propTypes:
5857
projectBlamer: RP.object.isRequired
5958
remoteRevision: RP.object.isRequired
60-
filePath: RP.string.isRequired
61-
lineCount: RP.number.isRequired
62-
scrollbar: RP.object.isRequired
59+
editorView: RP.object.isRequired
6360

6461
getInitialState: ->
6562
{
6663
# TODO: get this from the parent component somehow?
67-
scrollTop: @props.scrollbar.scrollTop()
64+
scrollTop: @scrollbar().scrollTop()
6865
# TODO: be intelligent about persisting this so it doesn't reset
6966
width: 210
7067
loading: true
7168
visible: true
69+
dirty: false
7270
}
7371

72+
scrollbar: ->
73+
@_scrollbar ?= @props.editorView.find('.vertical-scrollbar')
74+
75+
editor: ->
76+
@_editor ?= @props.editorView.getModel()
77+
7478
render: ->
7579
display = if @state.visible then 'inline-block' else 'none'
7680

@@ -84,9 +88,8 @@ BlameListView = React.createClass
8488
style: WebkitTransform: @getTransform()
8589
BlameListLinesComponent
8690
annotations: @state.annotations
87-
loading: @state.loading
88-
filePath: @props.filePath
89-
lineCount: @props.lineCount
91+
loading: @state.loading and not @state.dirty
92+
initialLineCount: @editor().getLineCount()
9093
remoteRevision: @props.remoteRevision
9194

9295
div
@@ -107,38 +110,54 @@ BlameListView = React.createClass
107110

108111
componentWillMount: ->
109112
# kick off async request for blame data
110-
@loadBlame true
111-
112-
loadBlame: (force) ->
113-
return if @state.loading and not force
113+
@loadBlame()
114+
@editor().on 'contents-modified', @contentsModified
115+
@editor().buffer.on 'saved', @saved
114116

117+
loadBlame: ->
115118
@setState loading: true
116-
@props.projectBlamer.blame @props.filePath, (err, data) =>
119+
@props.projectBlamer.blame @editor().getPath(), (err, data) =>
117120
if err
118121
@setState
119122
loading: false
120123
error: true
124+
dirty: false
121125
else
122126
@setState
123127
loading: false
124128
error: false
129+
dirty: false
125130
annotations: data
126131

132+
contentsModified: ->
133+
return unless @isMounted()
134+
@setState dirty: true unless @state.dirty
135+
136+
saved: ->
137+
return unless @isMounted()
138+
@loadBlame() if @state.visible and @state.dirty
139+
127140
toggle: ->
128-
@setState visible: !@state.visible
141+
if @state.visible
142+
@setState visible: false
143+
else
144+
@loadBlame() if @state.dirty
145+
@setState visible: true
129146

130147
componentDidMount: ->
131148
# Bind to scroll event on vertical-scrollbar to sync up scroll position of
132149
# blame gutter.
133-
@props.scrollbar.on 'scroll', @matchScrollPosition
150+
@scrollbar().on 'scroll', @matchScrollPosition
134151

135152
componentWillUnmount: ->
136-
@props.scrollbar.off 'scroll', @matchScrollPosition
153+
@scrollbar().off 'scroll', @matchScrollPosition
154+
@editor().off 'contents-modified', @contentsModified
155+
@editor().buffer.off 'saved', @saved
137156

138157
# Makes the view arguments scroll position match the target elements scroll
139158
# position
140159
matchScrollPosition: ->
141-
@setState scrollTop: @props.scrollbar.scrollTop()
160+
@setState scrollTop: @scrollbar().scrollTop()
142161

143162
resizeStarted: ({pageX}) ->
144163
@setState dragging: true, initialPageX: pageX, initialWidth: @state.width

0 commit comments

Comments
 (0)