Commits

Anonymous committed 1446af9

add triple-click line selection

  • Participants
  • Parent commits 05abc83

Comments (0)

Files changed (1)

lib/codemirror.js

     // whether the user is holding shift. reducedSelection is a hack
     // to get around the fact that we can't create inverted
     // selections. See below.
-    var shiftSelecting, reducedSelection;
+    var shiftSelecting, reducedSelection, lastDoubleClick;
     // Variables used by startOperation/endOperation to track what
     // happened during the operation.
     var updateInput, changes, textChanged, selectionChanged, leaveInputAlone;
     }
 
     function onMouseDown(e) {
+      var ld = lastDoubleClick; lastDoubleClick = null;
       // First, see if this is a click in the gutter
       for (var n = e.target(); n != wrapper; n = n.parentNode)
         if (n.parentNode == gutterText) {
       // selection.
       var start = posFromMouse(e), last = start, going;
       if (!start) {if (e.target() == wrapper) e.stop(); return;}
-      setCursor(start.line, start.ch, false);
 
       if (!focused) onFocus();
       e.stop();
+      if (ld && +new Date - ld < 400) return selectLine(start.line);
+
+      setCursor(start.line, start.ch, false);
       // And then we have to see if it's a drag event, in which case
       // the dragged-over text must be selected.
       function end() {
       if (!pos) return;
       selectWordAt(pos);
       e.stop();
+      lastDoubleClick = +new Date;
     }
     function onDrop(e) {
       var pos = posFromMouse(e, true), files = e.e.dataTransfer.files;
       while (end < line.length && /\w/.test(line.charAt(end))) ++end;
       setSelection({line: pos.line, ch: start}, {line: pos.line, ch: end});
     }
+    function selectLine(line) {
+      setSelection({line: line, ch: 0}, {line: line, ch: lines[line].text.length});
+    }
     function handleEnter() {
       replaceSelection("\n", "end");
       if (options.enterMode != "flat")