!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],t):t(CodeMirror)}(function(q){"use strict";var L=q.Pos;function k(t,e,r){return r?0<=t.indexOf(e):0==t.lastIndexOf(e,0)}q.registerHelper("hint","xml",function(t,e){var r=e&&e.schemaInfo,n=e&&e.quoteChar||'"',s=e&&e.matchInMiddle;if(r){var i=t.getCursor(),a=t.getTokenAt(i);a.end>i.ch&&(a.end=i.ch,a.string=a.string.slice(0,i.ch-a.start));var o=q.innerMode(t.getMode(),a.state);if("xml"==o.mode.name){var l,g,f=[],c=!1,h=/\btag\b/.test(a.type)&&!/>$/.test(a.string),p=h&&/^\w/.test(a.string);if(p){var u=t.getLine(i.line).slice(Math.max(0,a.start-2),a.start),d=/<\/$/.test(u)?"close":/<$/.test(u)?"open":null;d&&(g=a.start-("close"==d?2:1))}else h&&"<"==a.string?d="open":h&&"</"==a.string&&(d="close");if(!h&&!o.state.tagName||d){p&&(l=a.string),c=d;var m=o.state.context,v=m&&r[m.tagName],y=m?v&&v.children:r["!top"];if(y&&"close"!=d)for(var b=0;b<y.length;++b)l&&!k(y[b],l,s)||f.push("<"+y[b]);else if("close"!=d)for(var x in r)!r.hasOwnProperty(x)||"!top"==x||"!attrs"==x||l&&!k(x,l,s)||f.push("<"+x);m&&(!l||"close"==d&&k(m.tagName,l,s))&&f.push("</"+m.tagName+">")}else{var O=(v=r[o.state.tagName])&&v.attrs,w=r["!attrs"];if(!O&&!w)return;if(O){if(w){var A={};for(var M in w)w.hasOwnProperty(M)&&(A[M]=w[M]);for(var M in O)O.hasOwnProperty(M)&&(A[M]=O[M]);O=A}}else O=w;if("string"==a.type||"="==a.string){var P,N=(u=t.getRange(L(i.line,Math.max(0,i.ch-60)),L(i.line,"string"==a.type?a.start:a.end))).match(/([^\s\u00a0=<>\"\']+)=$/);if(!N||!O.hasOwnProperty(N[1])||!(P=O[N[1]]))return;if("function"==typeof P&&(P=P.call(this,t)),"string"==a.type){l=a.string;var $=0;/['"]/.test(a.string.charAt(0))&&(n=a.string.charAt(0),l=a.string.slice(1),$++);var C=a.string.length;if(/['"]/.test(a.string.charAt(C-1))&&(n=a.string.charAt(C-1),l=a.string.substr($,C-2)),$){var I=t.getLine(i.line);I.length>a.end&&I.charAt(a.end)==n&&a.end++}c=!0}for(b=0;b<P.length;++b)l&&!k(P[b],l,s)||f.push(n+P[b]+n)}else for(var j in"attribute"==a.type&&(l=a.string,c=!0),O)!O.hasOwnProperty(j)||l&&!k(j,l,s)||f.push(j)}return{list:f,from:c?L(i.line,null==g?a.start:g):i,to:c?L(i.line,a.end):i}}}})});