lib/assets/scripts/vendor/codemirror/codemirror.js
function updateSelectionRange(cm) {
    var display = cm.display, doc = cm.view.doc, sel = cm.view.sel;
    var fragment = document.createDocumentFragment();
    var clientWidth = display.lineSpace.offsetWidth, pl = paddingLeft(cm.display);

    function add(left, top, width, bottom) {
      if (top < 0) top = 0;
      fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
                               "px; top: " + top + "px; width: " + (width == null ? clientWidth - left : width) +
                               "px; height: " + (bottom - top) + "px"));
    }

    function drawForLine(line, fromArg, toArg, retTop) {
      var lineObj = getLine(doc, line);
      var lineLen = lineObj.text.length, rVal = retTop ? Infinity : -Infinity;
      function coords(ch) {
        return charCoords(cm, {line: line, ch: ch}, "div", lineObj);
      }

      iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
        var leftPos = coords(dir == "rtl" ? to - 1 : from);
        var rightPos = coords(dir == "rtl" ? from : to - 1);
        var left = leftPos.left, right = rightPos.right;
        if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
          add(left, leftPos.top, null, leftPos.bottom);
          left = pl;
          if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
        }
        if (toArg == null && to == lineLen) right = clientWidth;
        if (fromArg == null && from == 0) left = pl;
        rVal = retTop ? Math.min(rightPos.top, rVal) : Math.max(rightPos.bottom, rVal);
        if (left < pl + 1) left = pl;
        add(left, rightPos.top, right - left, rightPos.bottom);
      });
      return rVal;
    }

    if (sel.from.line == sel.to.line) {
      drawForLine(sel.from.line, sel.from.ch, sel.to.ch);
    } else {
      var fromObj = getLine(doc, sel.from.line);
      var cur = fromObj, merged, path = [sel.from.line, sel.from.ch], singleLine;
      while (merged = collapsedSpanAtEnd(cur)) {
        var found = merged.find();
        path.push(found.from.ch, found.to.line, found.to.ch);
        if (found.to.line == sel.to.line) {
          path.push(sel.to.ch);
          singleLine = true;
          break;
        }
        cur = getLine(doc, found.to.line);
      }

      // This is a single, merged line
      if (singleLine) {
        for (var i = 0; i < path.length; i += 3)
          drawForLine(path[i], path[i+1], path[i+2]);
      } else {
        var middleTop, middleBot, toObj = getLine(doc, sel.to.line);
        if (sel.from.ch)
          // Draw the first line of selection.
          middleTop = drawForLine(sel.from.line, sel.from.ch, null, false);
        else
          // Simply include it in the middle block.
          middleTop = heightAtLine(cm, fromObj) - display.viewOffset;

        if (!sel.to.ch)
          middleBot = heightAtLine(cm, toObj) - display.viewOffset;
        else
          middleBot = drawForLine(sel.to.line, collapsedSpanAtStart(toObj) ? null : 0, sel.to.ch, true);

        if (middleTop < middleBot) add(pl, middleTop, null, middleBot);
      }
    }

    removeChildrenAndAdd(display.selectionDiv, fragment);
    display.selectionDiv.style.display = "";
  }
function updateSelectionRange(cm) {
    var display = cm.display, doc = cm.view.doc, sel = cm.view.sel;
    var fragment = document.createDocumentFragment();
    var clientWidth = display.lineSpace.offsetWidth, pl = paddingLeft(cm.display);

    function add(left, top, width, bottom) {
      if (top < 0) top = 0;
      fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
                               "px; top: " + top + "px; width: " + (width == null ? clientWidth - left : width) +
                               "px; height: " + (bottom - top) + "px"));
    }

    function drawForLine(line, fromArg, toArg, retTop) {
      var lineObj = getLine(doc, line);
      var lineLen = lineObj.text.length, rVal = retTop ? Infinity : -Infinity;
      function coords(ch) {
        return charCoords(cm, {line: line, ch: ch}, "div", lineObj);
      }

      iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
        var leftPos = coords(dir == "rtl" ? to - 1 : from);
        var rightPos = coords(dir == "rtl" ? from : to - 1);
        var left = leftPos.left, right = rightPos.right;
        if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
          add(left, leftPos.top, null, leftPos.bottom);
          left = pl;
          if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
        }
        if (toArg == null && to == lineLen) right = clientWidth;
        if (fromArg == null && from == 0) left = pl;
        rVal = retTop ? Math.min(rightPos.top, rVal) : Math.max(rightPos.bottom, rVal);
        if (left < pl + 1) left = pl;
        add(left, rightPos.top, right - left, rightPos.bottom);
      });
      return rVal;
    }

    if (sel.from.line == sel.to.line) {
      drawForLine(sel.from.line, sel.from.ch, sel.to.ch);
    } else {
      var fromObj = getLine(doc, sel.from.line);
      var cur = fromObj, merged, path = [sel.from.line, sel.from.ch], singleLine;
      while (merged = collapsedSpanAtEnd(cur)) {
        var found = merged.find();
        path.push(found.from.ch, found.to.line, found.to.ch);
        if (found.to.line == sel.to.line) {
          path.push(sel.to.ch);
          singleLine = true;
          break;
        }
        cur = getLine(doc, found.to.line);
      }

      // This is a single, merged line
      if (singleLine) {
        for (var i = 0; i < path.length; i += 3)
          drawForLine(path[i], path[i+1], path[i+2]);
      } else {
        var middleTop, middleBot, toObj = getLine(doc, sel.to.line);
        if (sel.from.ch)
          // Draw the first line of selection.
          middleTop = drawForLine(sel.from.line, sel.from.ch, null, false);
        else
          // Simply include it in the middle block.
          middleTop = heightAtLine(cm, fromObj) - display.viewOffset;

        if (!sel.to.ch)
          middleBot = heightAtLine(cm, toObj) - display.viewOffset;
        else
          middleBot = drawForLine(sel.to.line, collapsedSpanAtStart(toObj) ? null : 0, sel.to.ch, true);

        if (middleTop < middleBot) add(pl, middleTop, null, middleBot);
      }
    }

    removeChildrenAndAdd(display.selectionDiv, fragment);
    display.selectionDiv.style.display = "";
  }
function updateSelectionRange ( cm ) { var display = cm . display , doc = cm . view . doc , sel = cm . view . sel ; var fragment = document . createDocumentFragment ( ) ; var clientWidth = display . lineSpace . offsetWidth , pl = paddingLeft ( cm . display ) ; function add ( left , top , width , bottom ) { if ( top < 0 ) top = 0 ; fragment . appendChild ( elt ( "div" , null , "CodeMirror-selected" , "position: absolute; left: " + left + "px; top: " + top + "px; width: " + ( width == null ? clientWidth - left : width ) + "px; height: " + ( bottom - top ) + "px" ) ) ; } function drawForLine ( line , fromArg , toArg , retTop ) { var lineObj = getLine ( doc , line ) ; var lineLen = lineObj . text . length , rVal = retTop ? Infinity : - Infinity ; function coords ( ch ) { return charCoords ( cm , { line : line , ch : ch } , "div" , lineObj ) ; } iterateBidiSections ( getOrder ( lineObj ) , fromArg || 0 , toArg == null ? lineLen : toArg , function ( from , to , dir ) { var leftPos = coords ( dir == "rtl" ? to - 1 : from ) ; var rightPos = coords ( dir == "rtl" ? from : to - 1 ) ; var left = leftPos . left , right = rightPos . right ; if ( rightPos . top - leftPos . top > 3 ) { // Different lines, draw top part add ( left , leftPos . top , null , leftPos . bottom ) ; left = pl ; if ( leftPos . bottom < rightPos . top ) add ( left , leftPos . bottom , null , rightPos . top ) ; } if ( toArg == null && to == lineLen ) right = clientWidth ; if ( fromArg == null && from == 0 ) left = pl ; rVal = retTop ? Math . min ( rightPos . top , rVal ) : Math . max ( rightPos . bottom , rVal ) ; if ( left < pl + 1 ) left = pl ; add ( left , rightPos . top , right - left , rightPos . bottom ) ; } ) ; return rVal ; } if ( sel . from . line == sel . to . line ) { drawForLine ( sel . from . line , sel . from . ch , sel . to . ch ) ; } else { var fromObj = getLine ( doc , sel . from . line ) ; var cur = fromObj , merged , path = [ sel . from . line , sel . from . ch ] , singleLine ; while ( merged = collapsedSpanAtEnd ( cur ) ) { var found = merged . find ( ) ; path . push ( found . from . ch , found . to . line , found . to . ch ) ; if ( found . to . line == sel . to . line ) { path . push ( sel . to . ch ) ; singleLine = true ; break ; } cur = getLine ( doc , found . to . line ) ; } // This is a single, merged line if ( singleLine ) { for ( var i = 0 ; i < path . length ; i += 3 ) drawForLine ( path [ i ] , path [ i + 1 ] , path [ i + 2 ] ) ; } else { var middleTop , middleBot , toObj = getLine ( doc , sel . to . line ) ; if ( sel . from . ch ) // Draw the first line of selection. middleTop = drawForLine ( sel . from . line , sel . from . ch , null , false ) ; else // Simply include it in the middle block. middleTop = heightAtLine ( cm , fromObj ) - display . viewOffset ; if ( ! sel . to . ch ) middleBot = heightAtLine ( cm , toObj ) - display . viewOffset ; else middleBot = drawForLine ( sel . to . line , collapsedSpanAtStart ( toObj ) ? null : 0 , sel . to . ch , true ) ; if ( middleTop < middleBot ) add ( pl , middleTop , null , middleBot ) ; } } removeChildrenAndAdd ( display . selectionDiv , fragment ) ; display . selectionDiv . style . display = "" ; }
Highlight selection
Highlight selection