2011-01-14 Ojan Vafai <ojan@chromium.org>
authorojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Jan 2011 19:21:40 +0000 (19:21 +0000)
committerojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Jan 2011 19:21:40 +0000 (19:21 +0000)
        Reviewed by Adam Barth.

        make line selection have a extend only from where you start the selection in the code review tool
        https://bugs.webkit.org/show_bug.cgi?id=52485

        * code-review.js:

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

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

index dd67ea32002d64e7383021bba5ba952d10381bf0..37fd553b3c0145985ad1c94424f762ba47b6edce 100644 (file)
@@ -1,3 +1,12 @@
+2011-01-14  Ojan Vafai  <ojan@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        make line selection have a extend only from where you start the selection in the code review tool
+        https://bugs.webkit.org/show_bug.cgi?id=52485
+
+        * code-review.js:
+
 2011-01-18  Ojan Vafai  <ojan@chromium.org>
 
         Reviewed by Eric Seidel.
index bdb938ebda61f6afd638b1d320efdee0d61ffb11..7961f779fd8fd430c0c0764412020eb0fb0d09bf 100644 (file)
     });
   }
 
-  var in_drag_select = false;
+  var drag_select_start_index = -1;
 
   function stopDragSelect() {
     $('.selected').removeClass('selected');
-    in_drag_select = false;
+    drag_select_start_index = -1;
   }
 
   function lineOffsetFrom(line, offset) {
     if (line.hasClass('commentContext'))
       trimCommentContextToBefore(previousLineFor(line), line.attr('data-comment-base-line'));
   }).live('mousedown', function() {
-    in_drag_select = true;
-    lineFromLineDescendant($(this)).addClass('selected');
+    var line = lineFromLineDescendant($(this));
+    drag_select_start_index = numberFrom(line.attr('id'));
+    line.addClass('selected');
     event.preventDefault();
   });
 
+  function selectTo(focus_index) {
+    var selected = $('.selected').removeClass('selected');
+    var is_backward = drag_select_start_index > focus_index;
+    var current_index = is_backward ? focus_index : drag_select_start_index;
+    var last_index = is_backward ? drag_select_start_index : focus_index;
+    while (current_index <= last_index) {
+      $('#line' + current_index).addClass('selected')
+      current_index++;
+    }
+  }
+
+  function selectToLineContainer(line_container) {
+    var line = lineFromLineContainer(line_container);
+    selectTo(numberFrom(line.attr('id')));
+  }
+
   $('.LineContainer').live('mouseenter', function() {
-    if (!in_drag_select)
+    if (drag_select_start_index == -1)
       return;
-
-    var line = lineFromLineContainer(this);
-    line.addClass('selected');
+    selectToLineContainer(this);
   }).live('mouseup', function() {
-    if (!in_drag_select)
+    if (drag_select_start_index == -1)
       return;
 
-    var selected = $('.selected');
-
-    // Select all the lines between the first and last selected lines
-    // in case we didn't get mouseenter events for any of them.
-    var current_index = numberFrom(selected.first().attr('id'));
-    var last_index = numberFrom(selected.last().attr('id'));
-    while (current_index != last_index) {
-      $('#line' + current_index).addClass('selected')
-      current_index++;
-    }
+    selectToLineContainer(this);
 
-    selected = $('.selected');
+    var selected = $('.selected');
     var already_has_comment = selected.last().hasClass('commentContext');
     selected.addClass('commentContext');