Вход Регистрация
Файл: engine/skins/mirror/addon/comment/continuecomment.js
Строк: 195
<?php
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE

(function(mod) {
  if (
typeof exports == "object" && typeof module == "object"// CommonJS
    
mod(require("../../lib/codemirror"));
  else if (
typeof define == "function" && define.amd// AMD
    
define(["../../lib/codemirror"], mod);
  else 
// Plain browser env
    
mod(CodeMirror);
})(function(
CodeMirror) {
  var 
modes = ["clike""css""javascript"];

  for (var 
0modes.length; ++i)
    
CodeMirror.extendMode(modes[i], {blockCommentContinue" * "});

  function 
continueComment(cm) {
    if (
cm.getOption("disableInput")) return CodeMirror.Pass;
    var 
ranges cm.listSelections(), modeinserts = [];
    for (var 
0ranges.lengthi++) {
      var 
pos ranges[i].headtoken cm.getTokenAt(pos);
      if (
token.type != "comment") return CodeMirror.Pass;
      var 
modeHere CodeMirror.innerMode(cm.getMode(), token.state).mode;
      if (!
modemode modeHere;
      else if (
mode != modeHere) return CodeMirror.Pass;

      var 
insert null;
      if (
mode.blockCommentStart && mode.blockCommentContinue) {
        var 
end token.string.indexOf(mode.blockCommentEnd);
        var 
full cm.getRange(CodeMirror.Pos(pos.line0), CodeMirror.Pos(pos.linetoken.end)), found;
        if (
end != -&& end == token.string.length mode.blockCommentEnd.length && pos.ch >= end) {
          
// Comment ended, don't continue it
        
} else if (token.string.indexOf(mode.blockCommentStart) == 0) {
          
insert full.slice(0token.start);
          if (!/^
s*$/.test(insert)) {
            
insert "";
            for (var 
0token.start; ++jinsert += " ";
          }
        } else if ((
found full.indexOf(mode.blockCommentContinue)) != -&&
                   
found mode.blockCommentContinue.length token.start &&
                   /^
s*$/.test(full.slice(0found))) {
          
insert full.slice(0found);
        }
        if (
insert != nullinsert += mode.blockCommentContinue;
      }
      if (
insert == null && mode.lineComment && continueLineCommentEnabled(cm)) {
        var 
line cm.getLine(pos.line), found line.indexOf(mode.lineComment);
        if (
found > -1) {
          
insert line.slice(0found);
          if (/
S/.test(insert)) insert null;
          else 
insert += mode.lineComment line.slice(found mode.lineComment.length).match(/^s*/)[0];
        }
      }
      if (
insert == null) return CodeMirror.Pass;
      
inserts[i] = "n" insert;
    }

    
cm.operation(function() {
      for (var 
ranges.length 1>= 0i--)
        
cm.replaceRange(inserts[i], ranges[i].from(), ranges[i].to(), "+insert");
    });
  }

  function 
continueLineCommentEnabled(cm) {
    var 
opt cm.getOption("continueComments");
    if (
opt && typeof opt == "object")
      return 
opt.continueLineComment !== false;
    return 
true;
  }

  
CodeMirror.defineOption("continueComments"null, function(cmvalprev) {
    if (
prev && prev != CodeMirror.Init)
      
cm.removeKeyMap("continueComment");
    if (
val) {
      var 
key "Enter";
      if (
typeof val == "string")
        
key val;
      else if (
typeof val == "object" && val.key)
        
key val.key;
      var 
map = {name"continueComment"};
      
map[key] = continueComment;
      
cm.addKeyMap(map);
    }
  });
});
?>
Онлайн: 1
Реклама