Changeset 3617:bb465743f804 for admin/js/codemirror/addon/edit
- Timestamp:
- 12/11/17 15:59:17 (8 years ago)
- Branch:
- default
- Location:
- admin/js/codemirror/addon/edit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/js/codemirror/addon/edit/closebrackets.js
r3532 r3617 24 24 } 25 25 if (val) { 26 ensureBound(getOption(val, "pairs")) 26 27 cm.state.closeBrackets = val; 27 28 cm.addKeyMap(keyMap); … … 35 36 } 36 37 37 var bind = defaults.pairs + "`";38 38 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 + "`") 41 46 42 47 function handler(ch) { … … 80 85 } 81 86 cm.operation(function() { 82 cm.replaceSelection("\n\n", null); 87 var linesep = cm.lineSeparator() || "\n"; 88 cm.replaceSelection(linesep + linesep, null); 83 89 cm.execCommand("goCharLeft"); 84 90 ranges = cm.listSelections(); … … 128 134 curType = "addFour"; 129 135 } 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"; 131 138 else return CodeMirror.Pass; 132 139 } else if (opening && (cm.getLine(cur.line).length == cur.ch || … … 180 187 } 181 188 182 // Project the token type that will exists after the given char is183 // typed, and use it to determine whether it would cause the start184 // 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 198 189 function stringStartsAfter(cm, pos) { 199 190 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))) 201 193 } 202 194 }); -
admin/js/codemirror/addon/edit/matchbrackets.js
r3532 r3617 17 17 var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"}; 18 18 19 function findMatchingBracket(cm, where, strict,config) {19 function findMatchingBracket(cm, where, config) { 20 20 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)]; 22 31 if (!match) return null; 23 32 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; 25 34 var style = cm.getTokenTypeAt(Pos(where.line, pos + 1)); 26 35 … … 70 79 var marks = [], ranges = cm.listSelections(); 71 80 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); 73 82 if (match && cm.getLine(match.from.line).length <= maxHighlightLen) { 74 83 var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket"; … … 114 123 115 124 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) 118 136 }); 119 137 CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){
Note: See TracChangeset
for help on using the changeset viewer.