1
1
{React , Reactionary , $ } = require ' atom'
2
- {div , span , a } = Reactionary
2
+ {div } = Reactionary
3
3
RP = React .PropTypes
4
4
_ = require ' underscore'
5
5
{BlameLineComponent , renderLoading } = require ' ./blame-line-view'
@@ -9,12 +9,11 @@ BlameListLinesComponent = React.createClass
9
9
propTypes :
10
10
annotations : RP .arrayOf (RP .object )
11
11
loading : RP .bool .isRequired
12
- filePath : RP .string .isRequired
13
- lineCount : RP .number .isRequired
12
+ initialLineCount : RP .number .isRequired
14
13
remoteRevision : RP .object .isRequired
15
14
16
15
renderLoading : ->
17
- lines = [0 ... @props .lineCount ].map renderLoading
16
+ lines = [0 ... @props .initialLineCount ].map renderLoading
18
17
div null , lines
19
18
20
19
# makes background color alternate by commit
@@ -57,20 +56,25 @@ BlameListView = React.createClass
57
56
propTypes :
58
57
projectBlamer : RP .object .isRequired
59
58
remoteRevision : RP .object .isRequired
60
- filePath : RP .string .isRequired
61
- lineCount : RP .number .isRequired
62
- scrollbar : RP .object .isRequired
59
+ editorView : RP .object .isRequired
63
60
64
61
getInitialState : ->
65
62
{
66
63
# TODO: get this from the parent component somehow?
67
- scrollTop : @props . scrollbar .scrollTop ()
64
+ scrollTop : @ scrollbar () .scrollTop ()
68
65
# TODO: be intelligent about persisting this so it doesn't reset
69
66
width : 210
70
67
loading : true
71
68
visible : true
69
+ dirty : false
72
70
}
73
71
72
+ scrollbar : ->
73
+ @_scrollbar ?= @props .editorView .find (' .vertical-scrollbar' )
74
+
75
+ editor : ->
76
+ @_editor ?= @props .editorView .getModel ()
77
+
74
78
render : ->
75
79
display = if @state .visible then ' inline-block' else ' none'
76
80
@@ -84,9 +88,8 @@ BlameListView = React.createClass
84
88
style : WebkitTransform : @ getTransform ()
85
89
BlameListLinesComponent
86
90
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 ()
90
93
remoteRevision : @props .remoteRevision
91
94
92
95
div
@@ -107,38 +110,54 @@ BlameListView = React.createClass
107
110
108
111
componentWillMount : ->
109
112
# 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
114
116
117
+ loadBlame : ->
115
118
@ setState loading : true
116
- @props .projectBlamer .blame @props . filePath , (err , data ) =>
119
+ @props .projectBlamer .blame @ editor (). getPath () , (err , data ) =>
117
120
if err
118
121
@setState
119
122
loading : false
120
123
error : true
124
+ dirty : false
121
125
else
122
126
@setState
123
127
loading : false
124
128
error : false
129
+ dirty : false
125
130
annotations : data
126
131
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
+
127
140
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
129
146
130
147
componentDidMount : ->
131
148
# Bind to scroll event on vertical-scrollbar to sync up scroll position of
132
149
# blame gutter.
133
- @props . scrollbar .on ' scroll' , @matchScrollPosition
150
+ @ scrollbar () .on ' scroll' , @matchScrollPosition
134
151
135
152
componentWillUnmount : ->
136
- @props .scrollbar .off ' scroll' , @matchScrollPosition
153
+ @ scrollbar ().off ' scroll' , @matchScrollPosition
154
+ @ editor ().off ' contents-modified' , @contentsModified
155
+ @ editor ().buffer .off ' saved' , @saved
137
156
138
157
# Makes the view arguments scroll position match the target elements scroll
139
158
# position
140
159
matchScrollPosition : ->
141
- @ setState scrollTop : @props . scrollbar .scrollTop ()
160
+ @ setState scrollTop : @ scrollbar () .scrollTop ()
142
161
143
162
resizeStarted : ({pageX}) ->
144
163
@ setState dragging : true , initialPageX : pageX, initialWidth : @state .width
0 commit comments