Skip to content

Commit ad2184f

Browse files
committed
Comment is placed on line of file instead of line of diff.
1 parent 83e1927 commit ad2184f

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

code_comments/comments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def get_condition_str_and_corresponding_values(self, args):
8787
elif name.endswith('__lt'):
8888
name = name.replace('__lt', '')
8989
conditions.append(name + ' < %s')
90+
elif name.endswith('__ne'):
91+
name = name.replace('__ne', '')
92+
conditions.append(name + ' != %s')
9093
elif name.endswith('__prefix'):
9194
values.append(args[name].replace('%', '\\%').replace('_', '\\_') + '%')
9295
name = name.replace('__prefix', '')

code_comments/htdocs/code-comments.js

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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'
@@ -235,7 +238,7 @@ var underscore = _.noConflict();
235238
var callbackMouseover = function( event ) {
236239
var row = new RowView( { el: this } ),
237240
file = row.getFile(),
238-
line = row.getLineNumberInDiff(),
241+
line = row.getLineNumberInFile(),
239242
displayLine = row.getLineNumberInFile(),
240243
displayLineText = displayLine;
241244
if (displayLine < 0) {
@@ -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

Comments
 (0)