0&&y g+p-3&&(c.scrollLeft=n+(m?0:10)-g),c}function Qi(t,e,i){null==e&&null==i||en(t),null!=e&&(t.curOp.scrollLeft=(null==t.curOp.scrollLeft?t.doc.scrollLeft:t.curOp.scrollLeft)+e),null!=i&&(t.curOp.scrollTop=(null==t.curOp.scrollTop?t.doc.scrollTop:t.curOp.scrollTop)+i)}function tn(t){en(t);var e=t.getCursor(),i=e,n=e;t.options.lineWrapping||(i=e.ch?O(e.line,e.ch-1):e,n=O(e.line,e.ch+1)),t.curOp.scrollToPos={from:i,to:n,margin:t.options.cursorScrollMargin,isCursor:!0}}function en(t){var e=t.curOp.scrollToPos;if(e){t.curOp.scrollToPos=null;var i=di(t,e.from),n=di(t,e.to),r=Zi(t,Math.min(i.left,n.left),Math.min(i.top,n.top)-e.margin,Math.max(i.right,n.right),Math.max(i.bottom,n.bottom)+e.margin);t.scrollTo(r.scrollLeft,r.scrollTop)}}function nn(t){t.curOp={cm:t,viewChanged:!1,startHeight:t.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++ra},we(t.curOp)}function rn(t){ke(t.curOp,function(t){for(var e=0;e0){if(s==o.length-1)return null;r=a+o[s].size-e,s++}else r=a-e;e+=r,i+=r}for(;ut(t.doc,i)!=i;){if(s==(n<0?0:o.length-1))return null;i+=n*o[s-(n<0?1:0)].size,s+=n}return{index:s,lineN:i}}function bn(t,e,i){var n=t.display;0==n.view.length||e>=n.viewTo||i<=n.viewFrom?(n.view=xe(t,e,i),n.viewFrom=e):(n.viewFrom>e?n.view=xe(t,e,n.viewFrom).concat(n.view):n.viewFromx&&r.push(new Dn(O(m,x),O(m,f(y,c,s))))}r.length||r.push(new Dn(i,i)),pr(h,In(g.ranges.slice(0,p).concat(r),p),{origin:"*mouse",scroll:!1}),t.scrollIntoView(e)}else{var w=d,C=w.anchor,k=e;if("single"!=n){var S;S="double"==n?t.findWordAt(e):new Dn(O(e.line,0),H(h,O(e.line+1,0))),D(S.anchor,C)>0?(k=S.head,C=z(w.from(),S.anchor)):(k=S.anchor,C=_(w.to(),S.head))}var M=g.ranges.slice(0);M[p]=new Dn(H(h,C),k),pr(h,In(M,p),$o)}}function a(e){var i=++w,r=Ci(t,e,!0,"rect"==n);if(r)if(0!=D(r,b)){t.curOp.focus=s(),o(r);var l=zi(c,h);(r.line>=l.to||r.lines&&(t=s,r=!0),n=T(this.doc,t)}else n=t;return li(this,n,{top:0,left:0},e||"page",i).top+(r?this.doc.height-pt(n):0)},defaultTextHeight:function(){return mi(this.display)},defaultCharWidth:function(){return vi(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(t,e,i,n,r){var s=this.display;t=hi(this,H(this.doc,t));var o=t.bottom,a=t.left;if(e.style.position="absolute",e.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(e),s.sizer.appendChild(e),"over"==n)o=t.top;else if("above"==n||"near"==n){var l=Math.max(s.wrapper.clientHeight,this.doc.height),c=Math.max(s.sizer.clientWidth,s.lineSpace.clientWidth);("above"==n||t.bottom+e.offsetHeight>l)&&t.top>e.offsetHeight?o=t.top-e.offsetHeight:t.bottom+e.offsetHeight<=l&&(o=t.bottom),a+e.offsetWidth>c&&(a=c-e.offsetWidth)}e.style.top=o+"px",e.style.left=e.style.right="","right"==r?(a=s.sizer.clientWidth-e.offsetWidth,e.style.right="0px"):("left"==r?a=0:"middle"==r&&(a=(s.sizer.clientWidth-e.offsetWidth)/2),e.style.left=a+"px"),i&&Ji(this,a,o,a+e.offsetWidth,o+e.offsetHeight)},triggerOnKeyDown:fn(ms),triggerOnKeyPress:fn(bs),triggerOnKeyUp:ys,execCommand:function(t){if(va.hasOwnProperty(t))return va[t].call(null,this)},triggerElectric:fn(function(t){Fs(this,t)}),findPosH:function(t,e,i,n){var r=this,s=1;e<0&&(s=-1,e=-e);for(var o=H(this.doc,t),a=0;a