+2011-01-11 Ojan Vafai <ojan@chromium.org>
+
+ Reviewed by Mihai Parparita.
+
+ fix exception when adding a comment to a side-by-side diff
+ https://bugs.webkit.org/show_bug.cgi?id=52240
+
+ prev() and next() won't get the previous and next lines in
+ side-by-side mode. Instead do a query to find them.
+
+ * code-review.js:
+
2011-01-11 Ojan Vafai <ojan@chromium.org>
Reviewed by Mihai Parparita.
in_drag_select = false;
}
+ function lineOffsetFrom(line, offset) {
+ var file_diff = line.parents('.FileDiff');
+ var all_lines = $('.Line', file_diff);
+ var index = all_lines.index(line);
+ return $(all_lines[index + offset]);
+ }
+
+ function previousLineFor(line) {
+ return lineOffsetFrom(line, -1);
+ }
+
+ function nextLineFor(line) {
+ return lineOffsetFrom(line, 1);
+ }
+
$('.lineNumber').live('click', function() {
var line = $(this).parent();
if (line.hasClass('commentContext'))
- trimCommentContextToBefore(line.prev());
+ trimCommentContextToBefore(previousLineFor(line));
}).live('mousedown', function() {
in_drag_select = true;
$(lineFromLineDescendant(this)).addClass('selected');
if (!in_drag_select)
return;
var selected = $('.selected');
- var should_add_comment = !selected.last().next().hasClass('commentContext');
+ var should_add_comment = !nextLineFor(selected.last()).hasClass('commentContext');
selected.addClass('commentContext');
var id;
addCommentFor($(last));
id = last.id;
} else {
- id = selected.last().next()[0].getAttribute('data-comment-base-line');
+ id = nextLineFor(selected.last())[0].getAttribute('data-comment-base-line');
}
selected.each(function() {