Skip to content

Commit 0b6ee53

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

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
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: 27 additions & 4 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,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

Comments
 (0)