@@ -35,7 +35,7 @@ var underscore = _.noConflict();
35
35
return this . fetch ( { data : _ . extend ( { line : 0 } , this . defaultFetchParams ) } ) ;
36
36
} ,
37
37
fetchLineComments : function ( ) {
38
- return this . fetch ( { data : _ . extend ( { line__gt : 0 } , this . defaultFetchParams ) } ) ;
38
+ return this . fetch ( { data : _ . extend ( { line__ne : 0 } , this . defaultFetchParams ) } ) ;
39
39
}
40
40
} ) ;
41
41
@@ -111,10 +111,11 @@ var underscore = _.noConflict();
111
111
} ,
112
112
addOne : function ( comment ) {
113
113
var line = comment . get ( 'line' ) ;
114
+ var file = comment . get ( 'path' ) ;
114
115
if ( ! this . viewPerLine [ line ] ) {
115
- this . viewPerLine [ line ] = new CommentsForALineView ( { line : line } ) ;
116
+ this . viewPerLine [ line ] = new CommentsForALineView ( { file : file , line : line } ) ;
116
117
117
- var $tr = $ ( Rows . getTrByLineNumberInDiff ( line ) ) ;
118
+ var $tr = $ ( Rows . getTrByFileAndLineNumberInFile ( file , line ) ) ;
118
119
$tr . after ( this . viewPerLine [ line ] . render ( ) . el ) . addClass ( 'with-comments' ) ;
119
120
}
120
121
this . viewPerLine [ line ] . addOne ( comment ) ;
@@ -133,6 +134,7 @@ var underscore = _.noConflict();
133
134
template : _ . template ( CodeComments . templates . comments_for_a_line ) ,
134
135
initialize : function ( attrs ) {
135
136
this . line = attrs . line ;
137
+ this . file = attrs . file ;
136
138
} ,
137
139
events : {
138
140
'click button' : 'showAddCommentDialog'
@@ -235,7 +237,7 @@ var underscore = _.noConflict();
235
237
var callbackMouseover = function ( event ) {
236
238
var row = new RowView ( { el : this } ) ,
237
239
file = row . getFile ( ) ,
238
- line = row . getLineNumberInDiff ( ) ,
240
+ line = row . getLineNumberInFile ( ) ,
239
241
displayLine = row . getLineNumberInFile ( ) ,
240
242
displayLineText = displayLine ;
241
243
if ( displayLine < 0 ) {
@@ -274,6 +276,27 @@ var underscore = _.noConflict();
274
276
getTrByLineNumberInDiff : function ( line ) {
275
277
return this . $rows [ line - 1 ] ;
276
278
} ,
279
+ getTrByFileAndLineNumberInFile : function ( file , line ) {
280
+ var containers = $ ( 'thead' , 'table.code, table.trac-diff' ) ;
281
+ var container ;
282
+ for ( var i = 0 ; ( container = containers [ i ] ) != null ; i ++ ) {
283
+ if ( $ ( container ) . parents ( 'li' ) . find ( 'h2>a:first' ) . text ( ) == file ) {
284
+ break ;
285
+ }
286
+ }
287
+ var trs = $ ( container ) . parents ( 'table' ) . find ( 'tbody>tr' ) . not ( '.comments' ) ;
288
+ var col = 1 ;
289
+ if ( line < 0 ) {
290
+ line = - line ;
291
+ col = 0 ;
292
+ }
293
+ for ( var i = 0 , tr ; ( tr = trs [ i ] ) != null ; i ++ ) {
294
+ if ( $ ( tr ) . find ( 'th>span' ) [ col ] . textContent == line ) {
295
+ return tr ;
296
+ }
297
+ }
298
+ return null ;
299
+ } ,
277
300
wrapTHsInSpans : function ( ) {
278
301
$ ( 'th' , this . $rows ) . each ( function ( i , elem ) {
279
302
elem . innerHTML = '<span>' + elem . innerHTML + '</span>' ;
0 commit comments