@@ -111,10 +111,11 @@ var underscore = _.noConflict();
111111 } ,
112112 addOne : function ( comment ) {
113113 var line = comment . get ( 'line' ) ;
114+ var file = comment . get ( 'path' ) ;
114115 if ( ! this . viewPerLine [ line ] ) {
115- this . viewPerLine [ line ] = new CommentsForALineView ( { line : line } ) ;
116+ this . viewPerLine [ line ] = new CommentsForALineView ( { file : file , line : line } ) ;
116117
117- var $tr = $ ( Rows . getTrByLineNumberInDiff ( line ) ) ;
118+ var $tr = $ ( Rows . getTrByFileAndLineNumberInFile ( file , line ) ) ;
118119 $tr . after ( this . viewPerLine [ line ] . render ( ) . el ) . addClass ( 'with-comments' ) ;
119120 }
120121 this . viewPerLine [ line ] . addOne ( comment ) ;
@@ -133,6 +134,7 @@ var underscore = _.noConflict();
133134 template : _ . template ( CodeComments . templates . comments_for_a_line ) ,
134135 initialize : function ( attrs ) {
135136 this . line = attrs . line ;
137+ this . file = attrs . file ;
136138 } ,
137139 events : {
138140 'click button' : 'showAddCommentDialog'
@@ -235,7 +237,7 @@ var underscore = _.noConflict();
235237 var callbackMouseover = function ( event ) {
236238 var row = new RowView ( { el : this } ) ,
237239 file = row . getFile ( ) ,
238- line = row . getLineNumberInDiff ( ) ,
240+ line = row . getLineNumberInFile ( ) ,
239241 displayLine = row . getLineNumberInFile ( ) ,
240242 displayLineText = displayLine ;
241243 if ( displayLine < 0 ) {
@@ -274,6 +276,27 @@ var underscore = _.noConflict();
274276 getTrByLineNumberInDiff : function ( line ) {
275277 return this . $rows [ line - 1 ] ;
276278 } ,
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+ } ,
277300 wrapTHsInSpans : function ( ) {
278301 $ ( 'th' , this . $rows ) . each ( function ( i , elem ) {
279302 elem . innerHTML = '<span>' + elem . innerHTML + '</span>' ;
0 commit comments