Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/cm/closebrackets.js

Issue 2862603003: Revert of DevTools: Roll CodeMirror to 5.25.1
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 // Distributed under an MIT license: http://codemirror.net/LICENSE 2 // Distributed under an MIT license: http://codemirror.net/LICENSE
3 3
4 (function(mod) { 4 (function(mod) {
5 if (typeof exports == "object" && typeof module == "object") // CommonJS 5 if (typeof exports == "object" && typeof module == "object") // CommonJS
6 mod(require("../../lib/codemirror")); 6 mod(require("../../lib/codemirror"));
7 else if (typeof define == "function" && define.amd) // AMD 7 else if (typeof define == "function" && define.amd) // AMD
8 define(["../../lib/codemirror"], mod); 8 define(["../../lib/codemirror"], mod);
9 else // Plain browser env 9 else // Plain browser env
10 mod(CodeMirror); 10 mod(CodeMirror);
(...skipping 27 matching lines...) Expand all
38 var keyMap = {Backspace: handleBackspace, Enter: handleEnter}; 38 var keyMap = {Backspace: handleBackspace, Enter: handleEnter};
39 for (var i = 0; i < bind.length; i++) 39 for (var i = 0; i < bind.length; i++)
40 keyMap["'" + bind.charAt(i) + "'"] = handler(bind.charAt(i)); 40 keyMap["'" + bind.charAt(i) + "'"] = handler(bind.charAt(i));
41 41
42 function handler(ch) { 42 function handler(ch) {
43 return function(cm) { return handleChar(cm, ch); }; 43 return function(cm) { return handleChar(cm, ch); };
44 } 44 }
45 45
46 function getConfig(cm) { 46 function getConfig(cm) {
47 var deflt = cm.state.closeBrackets; 47 var deflt = cm.state.closeBrackets;
48 if (!deflt || deflt.override) return deflt; 48 if (!deflt) return null;
49 var mode = cm.getModeAt(cm.getCursor()); 49 var mode = cm.getModeAt(cm.getCursor());
50 return mode.closeBrackets || deflt; 50 return mode.closeBrackets || deflt;
51 } 51 }
52 52
53 function handleBackspace(cm) { 53 function handleBackspace(cm) {
54 var conf = getConfig(cm); 54 var conf = getConfig(cm);
55 if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass; 55 if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
56 56
57 var pairs = getOption(conf, "pairs"); 57 var pairs = getOption(conf, "pairs");
58 var ranges = cm.listSelections(); 58 var ranges = cm.listSelections();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 var ranges = cm.listSelections(); 109 var ranges = cm.listSelections();
110 var opening = pos % 2 == 0; 110 var opening = pos % 2 == 0;
111 111
112 var type; 112 var type;
113 for (var i = 0; i < ranges.length; i++) { 113 for (var i = 0; i < ranges.length; i++) {
114 var range = ranges[i], cur = range.head, curType; 114 var range = ranges[i], cur = range.head, curType;
115 var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1)); 115 var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
116 if (opening && !range.empty()) { 116 if (opening && !range.empty()) {
117 curType = "surround"; 117 curType = "surround";
118 } else if ((identical || !opening) && next == ch) { 118 } else if ((identical || !opening) && next == ch) {
119 if (identical && stringStartsAfter(cm, cur)) 119 if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch)
120 curType = "both";
121 else if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur. ch + 3)) == ch + ch + ch)
122 curType = "skipThree"; 120 curType = "skipThree";
123 else 121 else
124 curType = "skip"; 122 curType = "skip";
125 } else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 && 123 } else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 &&
126 cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch && 124 cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch &&
127 (cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur. line, cur.ch - 2)) != ch)) { 125 (cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur. line, cur.ch - 2)) != ch)) {
128 curType = "addFour"; 126 curType = "addFour";
129 } else if (identical) { 127 } else if (identical) {
130 if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, ch)) curType = "both"; 128 if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, ch)) curType = "both";
131 else return CodeMirror.Pass; 129 else return CodeMirror.Pass;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 Pos(pos.line, pos.ch + 1)); 176 Pos(pos.line, pos.ch + 1));
179 return str.length == 2 ? str : null; 177 return str.length == 2 ? str : null;
180 } 178 }
181 179
182 // Project the token type that will exists after the given char is 180 // 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 181 // typed, and use it to determine whether it would cause the start
184 // of a string token. 182 // of a string token.
185 function enteringString(cm, pos, ch) { 183 function enteringString(cm, pos, ch) {
186 var line = cm.getLine(pos.line); 184 var line = cm.getLine(pos.line);
187 var token = cm.getTokenAt(pos); 185 var token = cm.getTokenAt(pos);
188 if (/\bstring2?\b/.test(token.type) || stringStartsAfter(cm, pos)) return fa lse; 186 if (/\bstring2?\b/.test(token.type)) return false;
189 var stream = new CodeMirror.StringStream(line.slice(0, pos.ch) + ch + line.s lice(pos.ch), 4); 187 var stream = new CodeMirror.StringStream(line.slice(0, pos.ch) + ch + line.s lice(pos.ch), 4);
190 stream.pos = stream.start = token.start; 188 stream.pos = stream.start = token.start;
191 for (;;) { 189 for (;;) {
192 var type1 = cm.getMode().token(stream, token.state); 190 var type1 = cm.getMode().token(stream, token.state);
193 if (stream.pos >= pos.ch + 1) return /\bstring2?\b/.test(type1); 191 if (stream.pos >= pos.ch + 1) return /\bstring2?\b/.test(type1);
194 stream.start = stream.pos; 192 stream.start = stream.pos;
195 } 193 }
196 } 194 }
197 195 });
198 function stringStartsAfter(cm, pos) {
199 var token = cm.getTokenAt(Pos(pos.line, pos.ch + 1))
200 return /\bstring/.test(token.type) && token.start == pos.ch
201 }
202 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698