@@ -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'
@@ -235,7 +238,7 @@ var underscore = _.noConflict();
235
238
var callbackMouseover = function ( event ) {
236
239
var row = new RowView ( { el : this } ) ,
237
240
file = row . getFile ( ) ,
238
- line = row . getLineNumberInDiff ( ) ,
241
+ line = row . getLineNumberInFile ( ) ,
239
242
displayLine = row . getLineNumberInFile ( ) ,
240
243
displayLineText = displayLine ;
241
244
if ( displayLine < 0 ) {
@@ -274,6 +277,34 @@ var underscore = _.noConflict();
274
277
getTrByLineNumberInDiff : function ( line ) {
275
278
return this . $rows [ line - 1 ] ;
276
279
} ,
280
+ getTrByFileAndLineNumberInFile : function ( file , line ) {
281
+ var col ;
282
+ var container ;
283
+ if ( CodeComments . page == "browser" && CodeComments . path == file ) {
284
+ container = $ ( 'thead' , 'table.code' ) ;
285
+ col = 0 ;
286
+ } else {
287
+ if ( line < 0 ) {
288
+ line = - line ;
289
+ col = 0 ;
290
+ } else {
291
+ col = 1
292
+ }
293
+ var containers = $ ( 'thead' , 'table.code, table.trac-diff' ) ;
294
+ for ( var i = 0 ; ( container = containers [ i ] ) != null ; i ++ ) {
295
+ if ( $ ( container ) . parents ( 'li' ) . find ( 'h2>a:first' ) . text ( ) == file ) {
296
+ break ;
297
+ }
298
+ }
299
+ }
300
+ var trs = $ ( container ) . parents ( 'table' ) . find ( 'tbody>tr' ) . not ( '.comments' ) ;
301
+ for ( var i = 0 , tr ; ( tr = trs [ i ] ) != null ; i ++ ) {
302
+ if ( $ ( tr ) . find ( 'th>span' ) [ col ] . textContent == line ) {
303
+ return tr ;
304
+ }
305
+ }
306
+ return null ;
307
+ } ,
277
308
wrapTHsInSpans : function ( ) {
278
309
$ ( 'th' , this . $rows ) . each ( function ( i , elem ) {
279
310
elem . innerHTML = '<span>' + elem . innerHTML + '</span>' ;
0 commit comments