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
// dirty hack for simple-hint to receive getHint event on space
16
var getTokenAt = editor.getTokenAt;
18
editor.getTokenAt = function() { return 'disabled'; };
19
CodeMirror.simpleHint(cm, getHint);
21
editor.getTokenAt = getTokenAt;
24
var getHint = function(cm) {
26
var cursor = cm.getCursor();
30
var text = cm.getRange({line: 0, ch: 0}, cursor);
33
for(var i = text.length - 1; i >= 0; i--) {
34
if(text[i] == ' ' || text[i] == '<') {
39
typed = text[i] + typed;
43
text = text.slice(0, text.length - typed.length);
45
var path = getActiveElement(cm, text) + simbol;
46
var hints = CodeMirror.xmlHints[path];
48
if(typeof hints === 'undefined')
51
hints = hints.slice(0);
52
for (var i = hints.length - 1; i >= 0; i--) {
53
if(hints[i].indexOf(typed) != 0)
60
from: { line: cursor.line, ch: cursor.ch - typed.length },
66
var getActiveElement = function(codeMirror, text) {
70
if(text.length >= 0) {
72
var regex = new RegExp('<([^!?][^\\s/>]*).*?>', 'g');
76
while ((match = regex.exec(text)) != null) {
79
selfclose: (match[0].slice(match[0].length - 2) === '/>')
83
for (var i = matches.length - 1, skip = 0; i >= 0; i--) {
85
var item = matches[i];
87
if (item.tag[0] == '/')
91
else if (item.selfclose == false)
99
element = '<' + item.tag + '>' + element;
104
element += getOpenTag(text);
110
var getOpenTag = function(text) {
112
var open = text.lastIndexOf('<');
113
var close = text.lastIndexOf('>');
117
text = text.slice(open);
121
var space = text.indexOf(' ');
123
space = text.indexOf('\t');
125
space = text.indexOf('\n');
130
return text.slice(0, space);