Dotclear


Ignore:
Timestamp:
12/11/17 15:59:17 (8 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Update CodeMirror? from 5.25.1 to 5.32.1

Location:
admin/js/codemirror/addon/edit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • admin/js/codemirror/addon/edit/closebrackets.js

    r3532 r3617  
    2424    } 
    2525    if (val) { 
     26      ensureBound(getOption(val, "pairs")) 
    2627      cm.state.closeBrackets = val; 
    2728      cm.addKeyMap(keyMap); 
     
    3536  } 
    3637 
    37   var bind = defaults.pairs + "`"; 
    3838  var keyMap = {Backspace: handleBackspace, Enter: handleEnter}; 
    39   for (var i = 0; i < bind.length; i++) 
    40     keyMap["'" + bind.charAt(i) + "'"] = handler(bind.charAt(i)); 
     39  function ensureBound(chars) { 
     40    for (var i = 0; i < chars.length; i++) { 
     41      var ch = chars.charAt(i), key = "'" + ch + "'" 
     42      if (!keyMap[key]) keyMap[key] = handler(ch) 
     43    } 
     44  } 
     45  ensureBound(defaults.pairs + "`") 
    4146 
    4247  function handler(ch) { 
     
    8085    } 
    8186    cm.operation(function() { 
    82       cm.replaceSelection("\n\n", null); 
     87      var linesep = cm.lineSeparator() || "\n"; 
     88      cm.replaceSelection(linesep + linesep, null); 
    8389      cm.execCommand("goCharLeft"); 
    8490      ranges = cm.listSelections(); 
     
    128134        curType = "addFour"; 
    129135      } else if (identical) { 
    130         if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, ch)) curType = "both"; 
     136        var prev = cur.ch == 0 ? " " : cm.getRange(Pos(cur.line, cur.ch - 1), cur) 
     137        if (!CodeMirror.isWordChar(next) && prev != ch && !CodeMirror.isWordChar(prev)) curType = "both"; 
    131138        else return CodeMirror.Pass; 
    132139      } else if (opening && (cm.getLine(cur.line).length == cur.ch || 
     
    180187  } 
    181188 
    182   // Project the token type that will exists after the given char is 
    183   // typed, and use it to determine whether it would cause the start 
    184   // of a string token. 
    185   function enteringString(cm, pos, ch) { 
    186     var line = cm.getLine(pos.line); 
    187     var token = cm.getTokenAt(pos); 
    188     if (/\bstring2?\b/.test(token.type) || stringStartsAfter(cm, pos)) return false; 
    189     var stream = new CodeMirror.StringStream(line.slice(0, pos.ch) + ch + line.slice(pos.ch), 4); 
    190     stream.pos = stream.start = token.start; 
    191     for (;;) { 
    192       var type1 = cm.getMode().token(stream, token.state); 
    193       if (stream.pos >= pos.ch + 1) return /\bstring2?\b/.test(type1); 
    194       stream.start = stream.pos; 
    195     } 
    196   } 
    197  
    198189  function stringStartsAfter(cm, pos) { 
    199190    var token = cm.getTokenAt(Pos(pos.line, pos.ch + 1)) 
    200     return /\bstring/.test(token.type) && token.start == pos.ch 
     191    return /\bstring/.test(token.type) && token.start == pos.ch && 
     192      (pos.ch == 0 || !/\bstring/.test(cm.getTokenTypeAt(pos))) 
    201193  } 
    202194}); 
  • admin/js/codemirror/addon/edit/matchbrackets.js

    r3532 r3617  
    1717  var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"}; 
    1818 
    19   function findMatchingBracket(cm, where, strict, config) { 
     19  function findMatchingBracket(cm, where, config) { 
    2020    var line = cm.getLineHandle(where.line), pos = where.ch - 1; 
    21     var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)]; 
     21    var afterCursor = config && config.afterCursor 
     22    if (afterCursor == null) 
     23      afterCursor = /(^| )cm-fat-cursor($| )/.test(cm.getWrapperElement().className) 
     24 
     25    // A cursor is defined as between two characters, but in in vim command mode 
     26    // (i.e. not insert mode), the cursor is visually represented as a 
     27    // highlighted box on top of the 2nd character. Otherwise, we allow matches 
     28    // from before or after the cursor. 
     29    var match = (!afterCursor && pos >= 0 && matching[line.text.charAt(pos)]) || 
     30        matching[line.text.charAt(++pos)]; 
    2231    if (!match) return null; 
    2332    var dir = match.charAt(1) == ">" ? 1 : -1; 
    24     if (strict && (dir > 0) != (pos == where.ch)) return null; 
     33    if (config && config.strict && (dir > 0) != (pos == where.ch)) return null; 
    2534    var style = cm.getTokenTypeAt(Pos(where.line, pos + 1)); 
    2635 
     
    7079    var marks = [], ranges = cm.listSelections(); 
    7180    for (var i = 0; i < ranges.length; i++) { 
    72       var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, false, config); 
     81      var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, config); 
    7382      if (match && cm.getLine(match.from.line).length <= maxHighlightLen) { 
    7483        var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket"; 
     
    114123 
    115124  CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);}); 
    116   CodeMirror.defineExtension("findMatchingBracket", function(pos, strict, config){ 
    117     return findMatchingBracket(this, pos, strict, config); 
     125  CodeMirror.defineExtension("findMatchingBracket", function(pos, config, oldConfig){ 
     126    // Backwards-compatibility kludge 
     127    if (oldConfig || typeof config == "boolean") { 
     128      if (!oldConfig) { 
     129        config = config ? {strict: true} : null 
     130      } else { 
     131        oldConfig.strict = config 
     132        config = oldConfig 
     133      } 
     134    } 
     135    return findMatchingBracket(this, pos, config) 
    118136  }); 
    119137  CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){ 
Note: See TracChangeset for help on using the changeset viewer.

Sites map