2011-01-11 Ojan Vafai <ojan@chromium.org>
authorojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Jan 2011 20:56:13 +0000 (20:56 +0000)
committerojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Jan 2011 20:56:13 +0000 (20:56 +0000)
        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:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75539 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/bugs.webkit.org/ChangeLog
Websites/bugs.webkit.org/code-review.js

index 4c4e5bdb575e979b5e5a86747baa9088c93f7019..76d0a83a8edeff14ab1c1124e21a6df9a666497b 100644 (file)
@@ -1,3 +1,15 @@
+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.
index cad12e3c23a299c29acb9d718c2654aeb26c988d..26dc13a798cebae5b85c2bc9efab53f061fe08ec 100644 (file)
     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() {