4 CodeMirror.xmlHints = [];
6 CodeMirror.xmlHint = function(cm, simbol) {
8 if(simbol.length > 0) {
9 var cursor = cm.getCursor();
10 cm.replaceSelection(simbol);
11 cursor = {line: cursor.line, ch: cursor.ch + 1};
15 CodeMirror.simpleHint(cm, getHint);
18 var getHint = function(cm) {
20 var cursor = cm.getCursor();
24 var text = cm.getRange({line: 0, ch: 0}, cursor);
27 for(var i = text.length - 1; i >= 0; i--) {
28 if(text[i] == ' ' || text[i] == '<') {
33 typed = text[i] + typed;
37 text = text.slice(0, text.length - typed.length);
39 var path = getActiveElement(text) + simbol;
40 var hints = CodeMirror.xmlHints[path];
42 if(typeof hints === 'undefined')
45 hints = hints.slice(0);
46 for (var i = hints.length - 1; i >= 0; i--) {
47 if(hints[i].indexOf(typed) != 0)
54 from: { line: cursor.line, ch: cursor.ch - typed.length },
60 var getActiveElement = function(text) {
64 if(text.length >= 0) {
66 var regex = new RegExp('<([^!?][^\\s/>]*).*?>', 'g');
70 while ((match = regex.exec(text)) != null) {
73 selfclose: (match[0].slice(match[0].length - 2) === '/>')
77 for (var i = matches.length - 1, skip = 0; i >= 0; i--) {
79 var item = matches[i];
81 if (item.tag[0] == '/')
85 else if (item.selfclose == false)
93 element = '<' + item.tag + '>' + element;
98 element += getOpenTag(text);
104 var getOpenTag = function(text) {
106 var open = text.lastIndexOf('<');
107 var close = text.lastIndexOf('>');
111 text = text.slice(open);
115 var space = text.indexOf(' ');
117 space = text.indexOf('\t');
119 space = text.indexOf('\n');
124 return text.slice(0, space);