@@ -35,7 +35,7 @@ var underscore = _.noConflict();
3535 return this . fetch ( { data : _ . extend ( { line : 0 } , this . defaultFetchParams ) } ) ;
3636 } ,
3737 fetchLineComments : function ( ) {
38- return this . fetch ( { data : _ . extend ( { line__gt : 0 } , this . defaultFetchParams ) } ) ;
38+ return this . fetch ( { data : _ . extend ( { line__ne : 0 } , this . defaultFetchParams ) } ) ;
3939 }
4040 } ) ;
4141
@@ -111,13 +111,15 @@ var underscore = _.noConflict();
111111 } ,
112112 addOne : function ( comment ) {
113113 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 } ) ;
116118
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' ) ;
119121 }
120- this . viewPerLine [ line ] . addOne ( comment ) ;
122+ this . viewPerLine [ key ] . addOne ( comment ) ;
121123 } ,
122124 addAll : function ( ) {
123125 var view = this ;
@@ -133,6 +135,7 @@ var underscore = _.noConflict();
133135 template : _ . template ( CodeComments . templates . comments_for_a_line ) ,
134136 initialize : function ( attrs ) {
135137 this . line = attrs . line ;
138+ this . file = attrs . file ;
136139 } ,
137140 events : {
138141 'click button' : 'showAddCommentDialog'
@@ -242,7 +245,7 @@ var underscore = _.noConflict();
242245 var callbackMouseover = function ( event ) {
243246 var row = new RowView ( { el : this } ) ,
244247 file = row . getFile ( ) ,
245- line = row . getLineNumberInDiff ( ) ,
248+ line = row . getLineNumberInFile ( ) ,
246249 displayLine = row . getLineNumberInFile ( ) ,
247250 displayLineText = displayLine ;
248251 if ( displayLine < 0 ) {
@@ -281,6 +284,34 @@ var underscore = _.noConflict();
281284 getTrByLineNumberInDiff : function ( line ) {
282285 return this . $rows [ line - 1 ] ;
283286 } ,
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+ } ,
284315 wrapTHsInSpans : function ( ) {
285316 $ ( 'th' , this . $rows ) . each ( function ( i , elem ) {
286317 elem . innerHTML = '<span>' + elem . innerHTML + '</span>' ;
0 commit comments