@@ -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,13 +111,15 @@ var underscore = _.noConflict();
111
111
} ,
112
112
addOne : function ( comment ) {
113
113
var line = comment . get ( 'line' ) ;
114
- if ( ! this . viewPerLine [ line ] ) {
115
- this . viewPerLine [ line ] = new CommentsForALineView ( { line : line } ) ;
114
+ var file = comment . get ( 'path' ) ;
115
+ var key = 'file_' + file + ':' + line ;
116
+ if ( ! this . viewPerLine [ key ] ) {
117
+ this . viewPerLine [ key ] = new CommentsForALineView ( { file : file , line : line } ) ;
116
118
117
- var $tr = $ ( Rows . getTrByLineNumberInDiff ( line ) ) ;
118
- $tr . after ( this . viewPerLine [ line ] . render ( ) . el ) . addClass ( 'with-comments' ) ;
119
+ var $tr = $ ( Rows . getTrByFileAndLineNumberInFile ( file , line ) ) ;
120
+ $tr . after ( this . viewPerLine [ key ] . render ( ) . el ) . addClass ( 'with-comments' ) ;
119
121
}
120
- this . viewPerLine [ line ] . addOne ( comment ) ;
122
+ this . viewPerLine [ key ] . addOne ( comment ) ;
121
123
} ,
122
124
addAll : function ( ) {
123
125
var view = this ;
@@ -133,6 +135,7 @@ var underscore = _.noConflict();
133
135
template : _ . template ( CodeComments . templates . comments_for_a_line ) ,
134
136
initialize : function ( attrs ) {
135
137
this . line = attrs . line ;
138
+ this . file = attrs . file ;
136
139
} ,
137
140
events : {
138
141
'click button' : 'showAddCommentDialog'
@@ -242,7 +245,7 @@ var underscore = _.noConflict();
242
245
var callbackMouseover = function ( event ) {
243
246
var row = new RowView ( { el : this } ) ,
244
247
file = row . getFile ( ) ,
245
- line = row . getLineNumberInDiff ( ) ,
248
+ line = row . getLineNumberInFile ( ) ,
246
249
displayLine = row . getLineNumberInFile ( ) ,
247
250
displayLineText = displayLine ;
248
251
if ( displayLine < 0 ) {
@@ -281,6 +284,34 @@ var underscore = _.noConflict();
281
284
getTrByLineNumberInDiff : function ( line ) {
282
285
return this . $rows [ line - 1 ] ;
283
286
} ,
287
+ getTrByFileAndLineNumberInFile : function ( file , line ) {
288
+ var col ;
289
+ var container ;
290
+ if ( CodeComments . page == "browser" && CodeComments . path == file ) {
291
+ container = $ ( 'thead' , 'table.code' ) ;
292
+ col = 0 ;
293
+ } else {
294
+ if ( line < 0 ) {
295
+ line = - line ;
296
+ col = 0 ;
297
+ } else {
298
+ col = 1
299
+ }
300
+ var containers = $ ( 'thead' , 'table.code, table.trac-diff' ) ;
301
+ for ( var i = 0 ; ( container = containers [ i ] ) != null ; i ++ ) {
302
+ if ( $ ( container ) . parents ( 'li' ) . find ( 'h2>a:first' ) . text ( ) == file ) {
303
+ break ;
304
+ }
305
+ }
306
+ }
307
+ var trs = $ ( container ) . parents ( 'table' ) . find ( 'tbody>tr' ) . not ( '.comments' ) ;
308
+ for ( var i = 0 , tr ; ( tr = trs [ i ] ) != null ; i ++ ) {
309
+ if ( $ ( tr ) . find ( 'th>span' ) [ col ] . textContent == line ) {
310
+ return tr ;
311
+ }
312
+ }
313
+ return null ;
314
+ } ,
284
315
wrapTHsInSpans : function ( ) {
285
316
$ ( 'th' , this . $rows ) . each ( function ( i , elem ) {
286
317
elem . innerHTML = '<span>' + elem . innerHTML + '</span>' ;
0 commit comments