(cm)
| 51 | "h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"]; |
| 52 | |
| 53 | function autoCloseGT(cm) { |
| 54 | if (cm.getOption("disableInput")) return CodeMirror.Pass; |
| 55 | var ranges = cm.listSelections(), replacements = []; |
| 56 | for (var i = 0; i < ranges.length; i++) { |
| 57 | if (!ranges[i].empty()) return CodeMirror.Pass; |
| 58 | var pos = ranges[i].head, tok = cm.getTokenAt(pos); |
| 59 | var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state; |
| 60 | if (inner.mode.name != "xml" || !state.tagName) return CodeMirror.Pass; |
| 61 | |
| 62 | var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html"; |
| 63 | var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose); |
| 64 | var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent); |
| 65 | |
| 66 | var tagName = state.tagName; |
| 67 | if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch); |
| 68 | var lowerTagName = tagName.toLowerCase(); |
| 69 | // Don't process the '>' at the end of an end-tag or self-closing tag |
| 70 | if (!tagName || |
| 71 | tok.type == "string" && (tok.end != pos.ch || !/[\"\']/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1) || |
| 72 | tok.type == "tag" && state.type == "closeTag" || |
| 73 | tok.string.indexOf("/") == (tok.string.length - 1) || // match something like <someTagName /> |
| 74 | dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1 || |
| 75 | closingTagExists(cm, tagName, pos, state, true)) |
| 76 | return CodeMirror.Pass; |
| 77 | |
| 78 | var indent = indentTags && indexOf(indentTags, lowerTagName) > -1; |
| 79 | replacements[i] = {indent: indent, |
| 80 | text: ">" + (indent ? "\n\n" : "") + "</" + tagName + ">", |
| 81 | newPos: indent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1)}; |
| 82 | } |
| 83 | |
| 84 | for (var i = ranges.length - 1; i >= 0; i--) { |
| 85 | var info = replacements[i]; |
| 86 | cm.replaceRange(info.text, ranges[i].head, ranges[i].anchor, "+insert"); |
| 87 | var sel = cm.listSelections().slice(0); |
| 88 | sel[i] = {head: info.newPos, anchor: info.newPos}; |
| 89 | cm.setSelections(sel); |
| 90 | if (info.indent) { |
| 91 | cm.indentLine(info.newPos.line, null, true); |
| 92 | cm.indentLine(info.newPos.line + 1, null, true); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | function autoCloseCurrent(cm, typingSlash) { |
| 98 | var ranges = cm.listSelections(), replacements = []; |
no test coverage detected