Вход Регистрация
Файл: upload/admin/view/javascript/ckeditor/plugins/codemirror/js/util/formatting.js
Строк: 215
<?php
(function() {

  
CodeMirror.extendMode("css", {
    
commentStart"/*",
    
commentEnd"*/",
    
newlineAfterToken: function(_typecontent) {
      return /^[;{}]$/.
test(content);
    }
  });

  
CodeMirror.extendMode("javascript", {
    
commentStart"/*",
    
commentEnd"*/",
    
// FIXME semicolons inside of for
    
newlineAfterToken: function(_typecontenttextAfterstate) {
      if (
this.jsonMode) {
        return /^[[,{]$/.
test(content) || /^}/.test(textAfter);
      } else {
        if (
content == ";" && state.lexical && state.lexical.type == ")") return false;
        return /^[;{}]$/.
test(content) && !/^;/.test(textAfter);
      }
    }
  });

  
CodeMirror.extendMode("xml", {
    
commentStart"<!--",
    
commentEnd"-->",
    
newlineAfterToken: function(typecontenttextAfter) {
      return 
type == "tag" && />$/.test(content) || /^</.test(textAfter);
    }
  });

  
// Comment/uncomment the specified range
  
CodeMirror.defineExtension("commentRange", function (isCommentfromto) {
    var 
cm thiscurMode CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(from).state).mode;
    
cm.operation(function() {
      if (
isComment) { // Comment range
        
cm.replaceRange(curMode.commentEndto);
        
cm.replaceRange(curMode.commentStartfrom);
        if (
from.line == to.line && from.ch == to.ch// An empty comment inserted - put cursor inside
          
cm.setCursor(from.linefrom.ch curMode.commentStart.length);
      } else { 
// Uncomment range
        
var selText cm.getRange(fromto);
        var 
startIndex selText.indexOf(curMode.commentStart);
        var 
endIndex selText.lastIndexOf(curMode.commentEnd);
        if (
startIndex > -&& endIndex > -&& endIndex startIndex) {
          
// Take string till comment start
          
selText selText.substr(0startIndex)
          
// From comment start till comment end
            
selText.substring(startIndex curMode.commentStart.lengthendIndex)
          
// From comment end till string end
            
selText.substr(endIndex curMode.commentEnd.length);
        }
        
cm.replaceRange(selTextfromto);
      }
    });
  });

  
// Applies automatic mode-aware indentation to the specified range
  
CodeMirror.defineExtension("autoIndentRange", function (fromto) {
    var 
cmInstance this;
    
this.operation(function () {
      for (var 
from.line<= to.linei++) {
        
cmInstance.indentLine(i"smart");
      }
    });
  });

  
// Applies automatic formatting to the specified range
  
CodeMirror.defineExtension("autoFormatRange", function (fromto) {
    var 
cm this;
    var 
outer cm.getMode(), text cm.getRange(fromto).split("n");
    var 
state CodeMirror.copyState(outercm.getTokenAt(from).state);
    var 
tabSize cm.getOption("tabSize");

    var 
out ""lines 0atSol from.ch == 0;
    function 
newline() {
      
out += "n";
      
atSol true;
      ++
lines;
    }

    for (var 
0text.length; ++i) {
      var 
stream = new CodeMirror.StringStream(text[i], tabSize);
      while (!
stream.eol()) {
        var 
inner CodeMirror.innerMode(outerstate);
        var 
style outer.token(streamstate), cur stream.current();
        
stream.start stream.pos;
        if (!
atSol || /S/.test(cur)) {
          
out += cur;
          
atSol false;
        }
        if (!
atSol && inner.mode.newlineAfterToken &&
            
inner.mode.newlineAfterToken(stylecurstream.string.slice(stream.pos) || text[i+1] || ""inner.state))
          
newline();
      }
      if (!
stream.pos && outer.blankLineouter.blankLine(state);
      if (!
atSolnewline();
    }

    
cm.operation(function () {
      
cm.replaceRange(outfromto);
      for (var 
cur from.line 1end from.line linescur <= end; ++cur)
        
cm.indentLine(cur"smart");
      
cm.setSelection(fromcm.getCursor(false));
    });
  });
})();
?>
Онлайн: 0
Реклама