Skip to content

Commit c7078dd

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 a06c315 commit c7078dd

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

@@ -230,13 +235,17 @@ var underscore = _.noConflict();
230235
var callbackMouseover = function( event ) {
231236
var row = new RowView( { el: this } ),
232237
file = row.getFile(),
233-
line = row.getLineNumber(),
234-
displayLine = row.getDisplayLine();
238+
line = row.getLineNumberInDiff(),
239+
displayLine = row.getLineNumberInFile(),
240+
displayLineText = displayLine;
241+
if (displayLine < 0) {
242+
displayLineText = -displayLine + ' (deleted)';
243+
}
235244
row.replaceLineNumberCellContent( '<a title="Comment on this line" href="#L' + line + '" class="bubble"><span class="ui-icon ui-icon-comment"></span></a>' );
236245

237246
$( 'a.bubble' ).click( function( e ) {
238247
e.preventDefault();
239-
AddCommentDialog.open( LineComments, line, file, displayLine );
248+
AddCommentDialog.open( LineComments, line, file, displayLineText );
240249
} );
241250
};
242251

@@ -294,11 +303,16 @@ var underscore = _.noConflict();
294303
getFile: function() {
295304
return this.$el.parents( 'li' ).find( 'h2>a:first' ).text();
296305
},
297-
getLineNumber: function() {
306+
getLineNumberInDiff: function() {
298307
return Rows.getLineByTR( this.el );
299308
},
300-
getDisplayLine: function() {
301-
return this.$lineNumberCell.text().trim() || this.$th.first().text() + ' (deleted)';
309+
getLineNumberInFile: function() {
310+
// Get the linenumber within the file of this row. If the row is deleted, return it negated.
311+
var l = this.$lineNumberCell.text().trim();
312+
if (l)
313+
return l;
314+
else
315+
return -this.$th.first().text().trim();
302316
}
303317
} );
304318

0 commit comments

Comments
 (0)