tianta/_server/CodeMirror/codeMirror.plugin.min.js

1 line
59 KiB
JavaScript
Raw Normal View History

2022-10-16 21:58:52 +08:00
!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(F){"use strict";var q="CodeMirror-hint-active";function i(e,t){this.cm=e,this.options=t,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 n=this;e.on("cursorActivity",this.activityFunc=function(){n.cursorActivity()})}F.showHint=function(e,t,n){if(!t)return e.showHint(n);n&&n.async&&(t.async=!0);var o={hint:t};if(n)for(var i in n)o[i]=n[i];return e.showHint(o)},F.defineExtension("showHint",function(e){e=function(e,t,n){var o=e.options.hintOptions,i={};for(var r in l)i[r]=l[r];if(o)for(var r in o)void 0!==o[r]&&(i[r]=o[r]);if(n)for(var r in n)void 0!==n[r]&&(i[r]=n[r]);i.hint.resolve&&(i.hint=i.hint.resolve(e,t));return i}(this,this.getCursor("start"),e);var t=this.listSelections();if(!(1<t.length)){if(this.somethingSelected()){if(!e.hint.supportsSelection)return;for(var n=0;n<t.length;n++)if(t[n].head.line!=t[n].anchor.line)return}this.state.completionActive&&this.state.completionActive.close();var o=this.state.completionActive=new i(this,e);o.options.hint&&(F.signal(this,"startCompletion",this),o.update(!0))}}),F.defineExtension("closeHint",function(){this.state.completionActive&&this.state.completionActive.close()});var o=window.requestAnimationFrame||function(e){return setTimeout(e,1e3/60)},r=window.cancelAnimationFrame||clearTimeout;function R(e){return"string"==typeof e?e:e.text}function D(e,t){for(;t&&t!=e;){if("LI"===t.nodeName.toUpperCase()&&t.parentNode==e)return t;t=t.parentNode}}function s(i,e){this.completion=i,this.data=e,this.picked=!1;var n=this,r=i.cm,s=r.getInputField().ownerDocument,a=s.defaultView||s.parentWindow,l=this.hints=s.createElement("ul"),t=i.cm.options.theme;l.className="CodeMirror-hints "+t,this.selectedHint=e.selectedHint||0;for(var o=e.list,c=0;c<o.length;++c){var f=l.appendChild(s.createElement("li")),u=o[c],h="CodeMirror-hint"+(c!=this.selectedHint?"":" "+q);null!=u.className&&(h=u.className+" "+h),f.className=h,u.render?u.render(f,e,u):f.appendChild(s.createTextNode(u.displayText||R(u))),f.hintId=c}var d,p,g,m=i.options.container||s.body,v=r.cursorCoords(i.options.alignWithWord?e.from:null),y=v.left,C=v.bottom,b=!0,x=0,k=0;m!==s.body&&(p=(d=-1!==["absolute","relative","fixed"].indexOf(a.getComputedStyle(m).position)?m:m.offsetParent).getBoundingClientRect(),g=s.body.getBoundingClientRect(),x=p.left-g.left-d.scrollLeft,k=p.top-g.top-d.scrollTop),l.style.left=y-x+"px",l.style.top=C-k+"px";var w=a.innerWidth||Math.max(s.body.offsetWidth,s.documentElement.offsetWidth),T=a.innerHeight||Math.max(s.body.offsetHeight,s.documentElement.offsetHeight);m.appendChild(l);var L,M,O=l.getBoundingClientRect(),A=O.bottom-T,S=l.scrollHeight>l.clientHeight+1,H=r.getScrollInfo();0<A&&(L=O.bottom-O.top,0<v.top-(v.bottom-O.top)-L?(l.style.top=(C=v.top-L-k)+"px",b=!1):T<L&&(l.style.height=T-5+"px",l.style.top=(C=v.bottom-O.top-k)+"px",M=r.getCursor(),e.from.ch!=M.ch&&(v=r.cursorCoords(M),l.style.left=(y=v.left-x)+"px",O=l.getBoundingClientRect())));var N,E=O.right-w;if(0<E&&(O.right-O.left>w&&(l.style.width=w-5+"px",E-=O.right-O.left-w),l.style.left=(y=v.left-E-x)+"px"),S)for(var P=l.firstChild;P;P=P.nextSibling)P.style.paddingRight=r.display.nativeBarWidth+"px";return r.addKeyMap(this.keyMap=function(e,o){var i={Up:function(){o.moveFocus(-1)},Down:function(){o.moveFocus(1)},PageUp:function(){o.moveFocus(1-o.menuSize(),!0)},PageDown:function(){o.moveFocus(o.menuSize()-1,!0)},Home:function(){o.setFocus(0)},End:function(){o.setFocus(o.length-1)},Enter:o.pick,Tab:o.pick,Esc:o.close};/Mac/.test(navigator.platform)&&(i["Ctrl-P"]=function(){o.moveFocus(-1)},i["Ctrl-N"]=function(){o.moveFocus(1)});var t=e.options.customKeys,r=t?{}:i;function n(e,t){var n="string"!=typeof t?function(e){return t(e,o)}:i.hasOwnProperty(t)?i[t]:t;r[e]=n}if(t)for(var s in t)t.hasOwnProperty(s)&&n(s,t[s]);var a=e.options.ex