!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){if(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,this.options.updateOnCursorActivity){var i=this;t.on("cursorActivity",this.activityFunc=function(){i.cursorActivity()})}}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 l)o[s]=l[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]);o.hint.resolve&&(o.hint=o.hint.resolve(t,e));return 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;oh.clientHeight+1;if(setTimeout((function(){T=c.getScrollInfo()})),F.bottom-M>0){var N=F.bottom-F.top;if(v.top-(v.bottom-F.top)-N>0)h.style.top=(b=v.top-N-H)+"px",w=!1;else if(N>M){h.style.height=M-5+"px",h.style.top=(b=v.bottom-F.top-H)+"px";var I=c.getCursor();i.from.ch!=I.ch&&(v=c.cursorCoords(I),h.style.left=(y=v.left-A)+"px",F=h.getBoundingClientRect())}}var P,E=F.right-S;if(O&&(E+=c.display.nativeBarWidth),E>0&&(F.right-F.left>S&&(h.style.width=S-5+"px",E-=F.right-F.left-S),h.style.left=(y=Math.max(v.left-E-A,0))+"px"),O)for(var W=h.firstChild;W;W=W.nextSibling)W.style.paddingRight=c.display.nativeBarWidth+"px";(c.addKeyMap(this.keyMap=function(t,e){var i={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)&&(i["Ctrl-P"]=function(){e.moveFocus(-1)},i["Ctrl-N"]=function(){e.moveFocus(1)});var n=t.options.customKeys,o=n?{}:i;function s(t,n){var s;s="string"!=typeof n?function(t){return n(t,e)}:i.hasOwnProperty(n)?i[n]:n,o[t]=s}if(n)for(var c in n)n.hasOwnProperty(c)&&s(c,n[c]);var r=t.options.extraKeys;if(r)for(var c in r)r.hasOwnProperty(c)&&s(c,r[c]);return o}(e,{moveFocus:function(t,e){n.changeActive(n.selectedHint+t,e)},setFocus:function(t){n.changeActive(t)},menuSize:function(){return n.screenAmount()},length:u.length,close:function(){e.close()},pick:function(){n.pick()},data:i})),e.options.closeOnUnfocus)&&(c.on("blur",this.onBlur=function(){P=setTimeout((function(){e.close()}),100)}),c.on("focus",this.onFocus=function(){clearTimeout(P)}));c.on("scroll",this.onScroll=function(){var t=c.getScrollInfo(),i=c.getWrapperElement().getBoundingClientRect();T||(T=c.getScrollInfo());var n=b+T.top-t.top,o=n-(l.pageYOffset||(r.documentElement||r.body).scrollTop);if(w||(o+=h.offsetHeight),o<=i.top||o>=i.bottom)return e.close();h.style.top=n+"px",h.style.left=y+T.left-t.left+"px"}),t.on(h,"dblclick",(function(t){var e=s(h,t.target||t.srcElement);e&&null!=e.hintId&&(n.changeActive(e.hintId),n.pick())})),t.on(h,"click",(function(t){var i=s(h,t.target||t.srcElement);i&&null!=i.hintId&&(n.changeActive(i.hintId),e.options.completeOnSingleClick&&n.pick())})),t.on(h,"mousedown",(function(){setTimeout((function(){c.focus()}),20)}));var R=this.getSelectedHintRange();return 0===R.from&&0===R.to||this.scrollToActive(),t.signal(i,"select",u[this.selectedHint],h.childNodes[this.selectedHint]),!0}function r(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)}}e.prototype={close:function(){this.active()&&(this.cm.state.completionActive=null,this.tick=null,this.options.updateOnCursorActivity&&this.cm.off("cursorActivity",this.activityFunc),this.widget&&this.data&&t.signal(this.data,"close"),this.widget&&this.widget.close(),t.signal(this.cm,"endCompletion",this.cm))},active:function(){return this.cm.state.completionActive==this},pick:function(e,i){var n=e.list[i],s=this;this.cm.operation((function(){n.hint?n.hint(s.cm,e,n):s.cm.replaceRange(o(n),n.from||e.from,n.to||e.to,"complete"),t.signal(e,"pick",n),s.cm.scrollIntoView()})),this.options.closeOnPick&&this.close()},cursorActivity:function(){this.debounce&&(n(this.debounce),this.debounce=0);var t=this.startPos;this.data&&(t=this.data.from);var e=this.cm.getCursor(),o=this.cm.getLine(e.line);if(e.line!=this.startPos.line||o.length-e.ch!=this.startLen-this.startPos.ch||e.ch=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(" CodeMirror-hint-active",""),n.removeAttribute("aria-selected")),(n=this.hints.childNodes[this.selectedHint=e]).className+=" CodeMirror-hint-active",n.setAttribute("aria-selected","true"),this.completion.cm.getInputField().setAttribute("aria-activedescendant",n.id),this.scrollToActive(),t.signal(this.data,"select",this.data.list[this.selectedHint],n)}},scrollToActive:function(){var t=this.getSelectedHintRange(),e=this.hints.childNodes[t.from],i=this.hints.childNodes[t.to],n=this.hints.firstChild;e.offsetTopthis.hints.scrollTop+this.hints.clientHeight&&(this.hints.scrollTop=i.offsetTop+i.offsetHeight-this.hints.clientHeight+n.offsetTop)},screenAmount:function(){return Math.floor(this.hints.clientHeight/this.hints.firstChild.offsetHeight)||1},getSelectedHintRange:function(){var t=this.completion.options.scrollMargin||0;return{from:Math.max(0,this.selectedHint-t),to:Math.min(this.data.list.length-1,this.selectedHint+t)}}},t.registerHelper("hint","auto",{resolve:function(e,i){var n,o=e.getHelpers(i,"hint");if(o.length){var s=function(t,e,i){var n=function(t,e){if(!t.somethingSelected())return e;for(var i=[],n=0;n0?e(t):o(s+1)}))}(0)};return s.async=!0,s.supportsSelection=!0,s}return(n=e.getHelper(e.getCursor(),"hintWords"))?function(e){return t.hint.fromList(e,{words:n})}:t.hint.anyword?function(e,i){return t.hint.anyword(e,i)}:function(){}}}),t.registerHelper("hint","fromList",(function(e,i){var n,o=e.getCursor(),s=e.getTokenAt(o),c=t.Pos(o.line,s.start),r=o;s.start,]/,closeOnPick:!0,closeOnUnfocus:!0,updateOnCursorActivity:!0,completeOnSingleClick:!0,container:null,customKeys:null,extraKeys:null,paddingForScrollbar:!0,moveOnOverlap:!0};t.defineOption("hintOptions",null)}));