(cm, ch)
| 115 | } |
| 116 | |
| 117 | function handleChar(cm, ch) { |
| 118 | var conf = getConfig(cm); |
| 119 | if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass; |
| 120 | |
| 121 | var pairs = getOption(conf, "pairs"); |
| 122 | var pos = pairs.indexOf(ch); |
| 123 | if (pos == -1) return CodeMirror.Pass; |
| 124 | |
| 125 | var closeBefore = getOption(conf,"closeBefore"); |
| 126 | |
| 127 | var triples = getOption(conf, "triples"); |
| 128 | |
| 129 | var identical = pairs.charAt(pos + 1) == ch; |
| 130 | var ranges = cm.listSelections(); |
| 131 | var opening = pos % 2 == 0; |
| 132 | |
| 133 | var type; |
| 134 | for (var i = 0; i < ranges.length; i++) { |
| 135 | var range = ranges[i], cur = range.head, curType; |
| 136 | var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1)); |
| 137 | if (opening && !range.empty()) { |
| 138 | curType = "surround"; |
| 139 | } else if ((identical || !opening) && next == ch) { |
| 140 | if (identical && stringStartsAfter(cm, cur)) |
| 141 | curType = "both"; |
| 142 | else if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch) |
| 143 | curType = "skipThree"; |
| 144 | else |
| 145 | curType = "skip"; |
| 146 | } else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 && |
| 147 | cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch) { |
| 148 | if (cur.ch > 2 && /\bstring/.test(cm.getTokenTypeAt(Pos(cur.line, cur.ch - 2)))) return CodeMirror.Pass; |
| 149 | curType = "addFour"; |
| 150 | } else if (identical) { |
| 151 | var prev = cur.ch == 0 ? " " : cm.getRange(Pos(cur.line, cur.ch - 1), cur) |
| 152 | if (!CodeMirror.isWordChar(next) && prev != ch && !CodeMirror.isWordChar(prev)) curType = "both"; |
| 153 | else return CodeMirror.Pass; |
| 154 | } else if (opening && (next.length === 0 || /\s/.test(next) || closeBefore.indexOf(next) > -1)) { |
| 155 | curType = "both"; |
| 156 | } else { |
| 157 | return CodeMirror.Pass; |
| 158 | } |
| 159 | if (!type) type = curType; |
| 160 | else if (type != curType) return CodeMirror.Pass; |
| 161 | } |
| 162 | |
| 163 | var left = pos % 2 ? pairs.charAt(pos - 1) : ch; |
| 164 | var right = pos % 2 ? ch : pairs.charAt(pos + 1); |
| 165 | cm.operation(function() { |
| 166 | if (type == "skip") { |
| 167 | moveSel(cm, 1) |
| 168 | } else if (type == "skipThree") { |
| 169 | moveSel(cm, 3) |
| 170 | } else if (type == "surround") { |
| 171 | var sels = cm.getSelections(); |
| 172 | for (var i = 0; i < sels.length; i++) |
| 173 | sels[i] = left + sels[i] + right; |
| 174 | cm.replaceSelections(sels, "around"); |
no test coverage detected