@@ -36,7 +36,7 @@ var underscore = _.noConflict();
3636 return this . fetch ( { data : _ . extend ( { line : 0 } , this . defaultFetchParams ) } ) ;
3737 } ,
3838 fetchLineComments : function ( ) {
39- return this . fetch ( { data : _ . extend ( { line__gt : 0 } , this . defaultFetchParams ) } ) ;
39+ return this . fetch ( { data : _ . extend ( { line__ne : 0 } , this . defaultFetchParams ) } ) ;
4040 }
4141 } ) ;
4242
@@ -112,13 +112,15 @@ var underscore = _.noConflict();
112112 } ,
113113 addOne : function ( comment ) {
114114 var line = comment . get ( 'line' ) ;
115- if ( ! this . viewPerLine [ line ] ) {
116- this . viewPerLine [ line ] = new CommentsForALineView ( { line : line } ) ;
115+ var file = comment . get ( 'path' ) ;
116+ var key = 'file_' + file + ':' + line ;
117+ if ( ! this . viewPerLine [ key ] ) {
118+ this . viewPerLine [ key ] = new CommentsForALineView ( { file : file , line : line } ) ;
117119
118- var $tr = $ ( Rows . getTrByLineNumberInDiff ( line ) ) ;
119- $tr . after ( this . viewPerLine [ line ] . render ( ) . el ) . addClass ( 'with-comments' ) ;
120+ var $tr = $ ( Rows . getTrByFileAndLineNumberInFile ( file , line ) ) ;
121+ $tr . after ( this . viewPerLine [ key ] . render ( ) . el ) . addClass ( 'with-comments' ) ;
120122 }
121- this . viewPerLine [ line ] . addOne ( comment ) ;
123+ this . viewPerLine [ key ] . addOne ( comment ) ;
122124 } ,
123125 addAll : function ( ) {
124126 var view = this ;
@@ -134,6 +136,7 @@ var underscore = _.noConflict();
134136 template : _ . template ( CodeComments . templates . comments_for_a_line ) ,
135137 initialize : function ( attrs ) {
136138 this . line = attrs . line ;
139+ this . file = attrs . file ;
137140 } ,
138141 events : {
139142 'click button' : 'showAddCommentDialog'
@@ -239,7 +242,7 @@ var underscore = _.noConflict();
239242 var callbackMouseover = function ( event ) {
240243 var row = new RowView ( { el : this } ) ,
241244 file = row . getFile ( ) ,
242- line = row . getLineNumberInDiff ( ) ,
245+ line = row . getLineNumberInFile ( ) ,
243246 displayLine = row . getDisplayLine ( ) ;
244247 row . replaceLineNumberCellContent ( '<a title="Comment on this line" href="#L' + line + '" class="bubble"><span class="ui-icon ui-icon-comment"></span></a>' ) ;
245248
@@ -274,6 +277,34 @@ var underscore = _.noConflict();
274277 getTrByLineNumberInDiff : function ( line ) {
275278 return this . $rows [ line - 1 ] ;
276279 } ,
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+ } ,
277308 wrapTHsInSpans : function ( ) {
278309 $ ( 'th' , this . $rows ) . each ( function ( i , elem ) {
279310 elem . innerHTML = '<span>' + elem . innerHTML + '</span>' ;
0 commit comments