!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],t):t(CodeMirror)}(function(t){"use strict";function e(t,e){this.cm=t,this.options=e,this.widget=null,this.debounce=0,this.tick=0,this.startPos=this.cm.getCursor("start"),this.startLen=this.cm.getLine(this.startPos.line).length-this.cm.getSelection().length;var i=this;t.on("cursorActivity",this.activityFunc=function(){i.cursorActivity()})}function i(t){return"string"==typeof t?t:t.text}function n(t,e){for(;e&&e!=t;){if("LI"===e.nodeName.toUpperCase()&&e.parentNode==t)return e;e=e.parentNode}}function o(e,o){this.completion=e,this.data=o,this.picked=!1;var s=this,l=e.cm,h=l.getInputField().ownerDocument,a=h.defaultView||h.parentWindow,f=this.hints=h.createElement("ul"),u=e.cm.options.theme;f.className="CodeMirror-hints "+u,this.selectedHint=o.selectedHint||0;for(var p=o.list,d=0;df.clientHeight+1,P=l.getScrollInfo();if(E>0){var W=N.bottom-N.top;if(w.top-(w.bottom-N.top)-W>0)f.style.top=(C=w.top-W-x)+"px",b=!1;else if(W>M){f.style.height=M-5+"px",f.style.top=(C=w.bottom-N.top-x)+"px";var I=l.getCursor();o.from.ch!=I.ch&&(w=l.cursorCoords(I),f.style.left=(H=w.left-k)+"px",N=f.getBoundingClientRect())}}var B=N.right-F;if(B>0&&(N.right-N.left>F&&(f.style.width=F-5+"px",B-=N.right-N.left-F),f.style.left=(H=w.left-B-k)+"px"),O)for(var K=f.firstChild;K;K=K.nextSibling)K.style.paddingRight=l.display.nativeBarWidth+"px";if(l.addKeyMap(this.keyMap=function(t,e){function i(t,i){var o;o="string"!=typeof i?function(t){return i(t,e)}:n.hasOwnProperty(i)?n[i]:i,s[t]=o}var n={Up:function(){e.moveFocus(-1)},Down:function(){e.moveFocus(1)},PageUp:function(){e.moveFocus(1-e.menuSize(),!0)},PageDown:function(){e.moveFocus(e.menuSize()-1,!0)},Home:function(){e.setFocus(0)},End:function(){e.setFocus(e.length-1)},Enter:e.pick,Tab:e.pick,Esc:e.close};/Mac/.test(navigator.platform)&&(n["Ctrl-P"]=function(){e.moveFocus(-1)},n["Ctrl-N"]=function(){e.moveFocus(1)});var o=t.options.customKeys,s=o?{}:n;if(o)for(var c in o)o.hasOwnProperty(c)&&i(c,o[c]);var r=t.options.extraKeys;if(r)for(var c in r)r.hasOwnProperty(c)&&i(c,r[c]);return s}(e,{moveFocus:function(t,e){s.changeActive(s.selectedHint+t,e)},setFocus:function(t){s.changeActive(t)},menuSize:function(){return s.screenAmount()},length:p.length,close:function(){e.close()},pick:function(){s.pick()},data:o})),e.options.closeOnUnfocus){var L;l.on("blur",this.onBlur=function(){L=setTimeout(function(){e.close()},100)}),l.on("focus",this.onFocus=function(){clearTimeout(L)})}return l.on("scroll",this.onScroll=function(){var t=l.getScrollInfo(),i=l.getWrapperElement().getBoundingClientRect(),n=C+P.top-t.top,o=n-(a.pageYOffset||(h.documentElement||h.body).scrollTop);if(b||(o+=f.offsetHeight),o<=i.top||o>=i.bottom)return e.close();f.style.top=n+"px",f.style.left=H+P.left-t.left+"px"}),t.on(f,"dblclick",function(t){var e=n(f,t.target||t.srcElement);e&&null!=e.hintId&&(s.changeActive(e.hintId),s.pick())}),t.on(f,"click",function(t){var i=n(f,t.target||t.srcElement);i&&null!=i.hintId&&(s.changeActive(i.hintId),e.options.completeOnSingleClick&&s.pick())}),t.on(f,"mousedown",function(){setTimeout(function(){l.focus()},20)}),t.signal(o,"select",p[this.selectedHint],f.childNodes[this.selectedHint]),!0}function s(t,e,i,n){if(t.async)t(e,n,i);else{var o=t(e,i);o&&o.then?o.then(n):n(o)}}var c="CodeMirror-hint",r="CodeMirror-hint-active";t.showHint=function(t,e,i){if(!e)return t.showHint(i);i&&i.async&&(e.async=!0);var n={hint:e};if(i)for(var o in i)n[o]=i[o];return t.showHint(n)},t.defineExtension("showHint",function(i){i=function(t,e,i){var n=t.options.hintOptions,o={};for(var s in a)o[s]=a[s];if(n)for(var s in n)void 0!==n[s]&&(o[s]=n[s]);if(i)for(var s in i)void 0!==i[s]&&(o[s]=i[s]);return o.hint.resolve&&(o.hint=o.hint.resolve(t,e)),o}(this,this.getCursor("start"),i);var n=this.listSelections();if(!(n.length>1)){if(this.somethingSelected()){if(!i.hint.supportsSelection)return;for(var o=0;o=this.data.list.length?e=i?this.data.list.length-1:0:e<0&&(e=i?0:this.data.list.length-1),this.selectedHint!=e){var n=this.hints.childNodes[this.selectedHint];n&&(n.className=n.className.replace(" "+r,"")),(n=this.hints.childNodes[this.selectedHint=e]).className+=" "+r,n.offsetTopthis.hints.scrollTop+this.hints.clientHeight&&(this.hints.scrollTop=n.offsetTop+n.offsetHeight-this.hints.clientHeight+3),t.signal(this.data,"select",this.data.list[this.selectedHint],n)}},screenAmount:function(){return Math.floor(this.hints.clientHeight/this.hints.firstChild.offsetHeight)||1}},t.registerHelper("hint","auto",{resolve:function(e,i){var n,o=e.getHelpers(i,"hint");if(o.length){var c=function(t,e,i){function n(o){if(o==c.length)return e(null);s(c[o],t,i,function(t){t&&t.list.length>0?e(t):n(o+1)})}var c=function(t,e){if(!t.somethingSelected())return e;for(var i=[],n=0;n,]/,closeOnUnfocus:!0,completeOnSingleClick:!0,container:null,customKeys:null,extraKeys:null};t.defineOption("hintOptions",null)});