Skip to content

Commit 0c4d546

Browse files
committed
Refactor functions for getting a line number
- Renamed the functions to reflect what they return - Descriptive text is added when immediately before displaying
1 parent 3d99bf6 commit 0c4d546

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

code_comments/htdocs/code-comments.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ var underscore = _.noConflict();
151151
},
152152
showAddCommentDialog: function() {
153153
row = new RowView( { el: $( this.el ).prev().get( 0 ) } );
154-
AddCommentDialog.open( LineComments, this.line, row.getFile(), row.getDisplayLine() );
154+
var displayLine = row.getLineNumberInFile();
155+
var displayLineText = displayLine;
156+
if (displayLine < 0) {
157+
displayLineText = -displayLine + ' (deleted)';
158+
}
159+
AddCommentDialog.open( LineComments, this.line, row.getFile(), displayLineText);
155160
}
156161
});
157162

@@ -237,13 +242,17 @@ var underscore = _.noConflict();
237242
var callbackMouseover = function( event ) {
238243
var row = new RowView( { el: this } ),
239244
file = row.getFile(),
240-
line = row.getLineNumber(),
241-
displayLine = row.getDisplayLine();
245+
line = row.getLineNumberInDiff(),
246+
displayLine = row.getLineNumberInFile(),
247+
displayLineText = displayLine;
248+
if (displayLine < 0) {
249+
displayLineText = -displayLine + ' (deleted)';
250+
}
242251
row.replaceLineNumberCellContent( '<a title="Comment on this line" href="#L' + line + '" class="bubble"><span class="ui-icon ui-icon-comment"></span></a>' );
243252

244253
$( 'a.bubble' ).click( function( e ) {
245254
e.preventDefault();
246-
AddCommentDialog.open( LineComments, line, file, displayLine );
255+
AddCommentDialog.open( LineComments, line, file, displayLineText );
247256
} );
248257
};
249258

@@ -301,11 +310,16 @@ var underscore = _.noConflict();
301310
getFile: function() {
302311
return this.$el.parents( 'li' ).find( 'h2>a:first' ).text();
303312
},
304-
getLineNumber: function() {
313+
getLineNumberInDiff: function() {
305314
return Rows.getLineByTR( this.el );
306315
},
307-
getDisplayLine: function() {
308-
return this.$lineNumberCell.text().trim() || this.$th.first().text() + ' (deleted)';
316+
getLineNumberInFile: function() {
317+
// Get the linenumber within the file of this row. If the row is deleted, return it negated.
318+
var l = this.$lineNumberCell.text().trim();
319+
if (l)
320+
return l;
321+
else
322+
return -this.$th.first().text().trim();
309323
}
310324
} );
311325

0 commit comments

Comments
 (0)