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

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

Issue 2772343006: DevTools: Roll CodeMirror to 5.25.1 (Closed)
Patch Set: stray space Created 3 years, 8 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) return null; 48 if (!deflt || deflt.override) return deflt;
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 (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch) 119 if (identical && stringStartsAfter(cm, cur))
120 curType = "both";
121 else if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur. ch + 3)) == ch + ch + ch)
120 curType = "skipThree"; 122 curType = "skipThree";
121 else 123 else
122 curType = "skip"; 124 curType = "skip";
123 } else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 && 125 } else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 &&
124 cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch && 126 cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch &&
125 (cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur. line, cur.ch - 2)) != ch)) { 127 (cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur. line, cur.ch - 2)) != ch)) {
126 curType = "addFour"; 128 curType = "addFour";
127 } else if (identical) { 129 } else if (identical) {
128 if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, ch)) curType = "both"; 130 if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, ch)) curType = "both";
129 else return CodeMirror.Pass; 131 else return CodeMirror.Pass;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 Pos(pos.line, pos.ch + 1)); 178 Pos(pos.line, pos.ch + 1));
177 return str.length == 2 ? str : null; 179 return str.length == 2 ? str : null;
178 } 180 }
179 181
180 // Project the token type that will exists after the given char is 182 // Project the token type that will exists after the given char is
181 // typed, and use it to determine whether it would cause the start 183 // typed, and use it to determine whether it would cause the start
182 // of a string token. 184 // of a string token.
183 function enteringString(cm, pos, ch) { 185 function enteringString(cm, pos, ch) {
184 var line = cm.getLine(pos.line); 186 var line = cm.getLine(pos.line);
185 var token = cm.getTokenAt(pos); 187 var token = cm.getTokenAt(pos);
186 if (/\bstring2?\b/.test(token.type)) return false; 188 if (/\bstring2?\b/.test(token.type) || stringStartsAfter(cm, pos)) return fa lse;
187 var stream = new CodeMirror.StringStream(line.slice(0, pos.ch) + ch + line.s lice(pos.ch), 4); 189 var stream = new CodeMirror.StringStream(line.slice(0, pos.ch) + ch + line.s lice(pos.ch), 4);
188 stream.pos = stream.start = token.start; 190 stream.pos = stream.start = token.start;
189 for (;;) { 191 for (;;) {
190 var type1 = cm.getMode().token(stream, token.state); 192 var type1 = cm.getMode().token(stream, token.state);
191 if (stream.pos >= pos.ch + 1) return /\bstring2?\b/.test(type1); 193 if (stream.pos >= pos.ch + 1) return /\bstring2?\b/.test(type1);
192 stream.start = stream.pos; 194 stream.start = stream.pos;
193 } 195 }
194 } 196 }
195 }); 197
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