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,12 @@ 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
+ dirty : RP .bool .isRequired
13
+ initialLineCount : RP .number .isRequired
14
14
remoteRevision : RP .object .isRequired
15
15
16
16
renderLoading : ->
17
- lines = [0 ... @props .lineCount ].map renderLoading
17
+ lines = [0 ... @props .initialLineCount ].map renderLoading
18
18
div null , lines
19
19
20
20
# makes background color alternate by commit
@@ -49,28 +49,34 @@ BlameListLinesComponent = React.createClass
49
49
else
50
50
@ renderLoaded ()
51
51
52
- shouldComponentUpdate : ({loading}) ->
53
- loading isnt @props .loading
54
-
52
+ shouldComponentUpdate : ({loading, dirty}) ->
53
+ finishedInitialLoad = @props .loading and not loading and not @props .dirty
54
+ finishedEdit = @props .dirty and not dirty
55
+ finishedInitialLoad or finishedEdit
55
56
56
57
BlameListView = React .createClass
57
58
propTypes :
58
59
projectBlamer : RP .object .isRequired
59
60
remoteRevision : RP .object .isRequired
60
- filePath : RP .string .isRequired
61
- lineCount : RP .number .isRequired
62
- scrollbar : RP .object .isRequired
61
+ editorView : RP .object .isRequired
63
62
64
63
getInitialState : ->
65
64
{
66
65
# TODO: get this from the parent component somehow?
67
- scrollTop : @props . scrollbar .scrollTop ()
66
+ scrollTop : @ scrollbar () .scrollTop ()
68
67
# TODO: be intelligent about persisting this so it doesn't reset
69
68
width : 210
70
69
loading : true
71
70
visible : true
71
+ dirty : false
72
72
}
73
73
74
+ scrollbar : ->
75
+ @_scrollbar ?= @props .editorView .find (' .vertical-scrollbar' )
76
+
77
+ editor : ->
78
+ @_editor ?= @props .editorView .getModel ()
79
+
74
80
render : ->
75
81
display = if @state .visible then ' inline-block' else ' none'
76
82
@@ -85,10 +91,9 @@ BlameListView = React.createClass
85
91
BlameListLinesComponent
86
92
annotations : @state .annotations
87
93
loading : @state .loading
88
- filePath : @props . filePath
89
- lineCount : @props . lineCount
94
+ dirty : @state . dirty
95
+ initialLineCount : @ editor (). getLineCount ()
90
96
remoteRevision : @props .remoteRevision
91
-
92
97
div
93
98
className : ' git-blame'
94
99
style : width : @state .width , display : display
@@ -107,38 +112,54 @@ BlameListView = React.createClass
107
112
108
113
componentWillMount : ->
109
114
# kick off async request for blame data
110
- @ loadBlame true
111
-
112
- loadBlame : (force ) ->
113
- return if @state .loading and not force
115
+ @ loadBlame ()
116
+ @ editor ().on ' contents-modified' , @contentsModified
117
+ @ editor ().buffer .on ' saved' , @saved
114
118
119
+ loadBlame : ->
115
120
@ setState loading : true
116
- @props .projectBlamer .blame @props . filePath , (err , data ) =>
121
+ @props .projectBlamer .blame @ editor (). getPath () , (err , data ) =>
117
122
if err
118
123
@setState
119
124
loading : false
120
125
error : true
126
+ dirty : false
121
127
else
122
128
@setState
123
129
loading : false
124
130
error : false
131
+ dirty : false
125
132
annotations : data
126
133
134
+ contentsModified : ->
135
+ return unless @ isMounted ()
136
+ @ setState dirty : true unless @state .dirty
137
+
138
+ saved : ->
139
+ return unless @ isMounted ()
140
+ @ loadBlame () if @state .visible and @state .dirty
141
+
127
142
toggle : ->
128
- @ setState visible : ! @state .visible
143
+ if @state .visible
144
+ @ setState visible : false
145
+ else
146
+ @ loadBlame () if @state .dirty
147
+ @ setState visible : true
129
148
130
149
componentDidMount : ->
131
150
# Bind to scroll event on vertical-scrollbar to sync up scroll position of
132
151
# blame gutter.
133
- @props . scrollbar .on ' scroll' , @matchScrollPosition
152
+ @ scrollbar () .on ' scroll' , @matchScrollPosition
134
153
135
154
componentWillUnmount : ->
136
- @props .scrollbar .off ' scroll' , @matchScrollPosition
155
+ @ scrollbar ().off ' scroll' , @matchScrollPosition
156
+ @ editor ().off ' contents-modified' , @contentsModified
157
+ @ editor ().buffer .off ' saved' , @saved
137
158
138
159
# Makes the view arguments scroll position match the target elements scroll
139
160
# position
140
161
matchScrollPosition : ->
141
- @ setState scrollTop : @props . scrollbar .scrollTop ()
162
+ @ setState scrollTop : @ scrollbar () .scrollTop ()
142
163
143
164
resizeStarted : ({pageX}) ->
144
165
@ setState dragging : true , initialPageX : pageX, initialWidth : @state .width
0 commit comments