A hack to fix jumping cursor issue of wodoeditor

This commit is contained in:
Hadi Nategh 2016-11-10 14:12:35 +01:00
parent e9155a000b
commit ad2c3674e5

View File

@ -442,8 +442,8 @@ return g}var k=odf.OdfUtils,a=new odf.StepUtils,e=core.DomUtils,c=core.StepDirec
d?(l=b,y=k):(l=k,y=b),b=g.reduce(h,!1);while(!b&&a.advanceStep(e));b||g.forEach(function(b){!t&&b.token&&(t=b.token)});a.restore(t||z);return Boolean(t)}};gui.Caret=function(f,k,a,e){function c(){h.style.opacity="0"===h.style.opacity?"1":"0";x.trigger()}function m(){l.selectNodeContents(r);return l.getBoundingClientRect()}function n(){Object.keys(D).forEach(function(b){G[b]=D[b]})}function p(){if(!1===D.isShown||f.getSelectionType()!==ops.OdtCursor.RangeSelection||!e&&!f.getSelectedRange().collapsed)D.visibility="hidden",h.style.visibility="hidden",x.cancel();else if(D.visibility="visible",h.style.visibility="visible",!1===D.isFocused)h.style.opacity=
"1",x.cancel();else{if(u||G.visibility!==D.visibility)h.style.opacity="1",x.cancel();x.trigger()}if(H||C){var a;a=f.getNode();var c,l,r=t.getBoundingClientRect(y.getSizer()),p=!1,q=0;a.removeAttributeNS("urn:webodf:names:cursor","caret-sizer-active");if(0<a.getClientRects().length)l=m(),q=l.left-t.getBoundingClientRect(a).left,p=!0;else if(w.setPosition(a,0),l=z.getContentRect(w),!l&&w.nextStep()&&(c=z.getContentRect(w))&&(l=c,p=!0),l||(a.setAttributeNS("urn:webodf:names:cursor","caret-sizer-active",
"true"),l=m(),p=!0),!l)for(runtime.log("WARN: No suitable client rectangle found for visual caret for "+f.getMemberId());a;){if(0<a.getClientRects().length){l=t.getBoundingClientRect(a);p=!0;break}a=a.parentNode}l=t.translateRect(l,r,y.getZoomLevel());a={top:l.top,height:l.height,right:p?l.left:l.right,width:t.adaptRangeDifferenceToZoomLevel(q,y.getZoomLevel())};8>a.height&&(a={top:a.top-(8-a.height)/2,height:8,right:a.right});g.style.height=a.height+"px";g.style.top=a.top+"px";g.style.left=a.right-
a.width+"px";g.style.width=a.width?a.width+"px":"";b&&(a=runtime.getWindow().getComputedStyle(f.getNode(),null),a.font?b.style.font=a.font:(b.style.fontStyle=a.fontStyle,b.style.fontVariant=a.fontVariant,b.style.fontWeight=a.fontWeight,b.style.fontSize=a.fontSize,b.style.lineHeight=a.lineHeight,b.style.fontFamily=a.fontFamily))}D.isShown&&C&&k.scrollIntoView(h.getBoundingClientRect());G.isFocused!==D.isFocused&&d.markAsFocussed(D.isFocused);n();H=C=u=!1}function q(b){g.parentNode.removeChild(g);r.parentNode.removeChild(r);
b()}var g,h,d,b,r,l,y=f.getDocument().getCanvas(),t=core.DomUtils,z=new gui.GuiStepUtils,w,s,x,u=!1,C=!1,H=!1,D={isFocused:!1,isShown:!0,visibility:"hidden"},G={isFocused:!D.isFocused,isShown:!D.isShown,visibility:"hidden"};this.handleUpdate=function(){H=!0;s.trigger()};this.refreshCursorBlinking=function(){u=!0;s.trigger()};this.setFocus=function(){D.isFocused=!0;s.trigger()};this.removeFocus=function(){D.isFocused=!1;s.trigger()};this.show=function(){D.isShown=!0;s.trigger()};this.hide=function(){D.isShown=
a.width+"px";g.style.width=a.width?a.width+"px":"";b&&(a=runtime.getWindow().getComputedStyle(f.getNode(),null),a.font?b.style.font=a.font:(b.style.fontStyle=a.fontStyle,b.style.fontVariant=a.fontVariant,b.style.fontWeight=a.fontWeight,b.style.fontSize=a.fontSize,b.style.lineHeight=a.lineHeight,b.style.fontFamily=a.fontFamily))}!G.isScrolled&&D.isShown&&C&&k.scrollIntoView(h.getBoundingClientRect());G.isFocused!==D.isFocused&&d.markAsFocussed(D.isFocused);n();H=C=u=!1}function q(b){g.parentNode.removeChild(g);r.parentNode.removeChild(r);
b()}var g,h,d,b,r,l,y=f.getDocument().getCanvas(),t=core.DomUtils,z=new gui.GuiStepUtils,w,s,x,u=!1,C=!1,H=!1,D={isFocused:!1,isShown:!0,visibility:"hidden"},G={isFocused:!D.isFocused,isShown:!D.isShown,visibility:"hidden"};jQuery('.webodfeditor-canvascontainer').off().on('keyup scroll', function(e){if(e.which){G.isScrolled = false;return;}G.isScrolled = true;});this.handleUpdate=function(){H=!0;s.trigger()};this.refreshCursorBlinking=function(){u=!0;s.trigger()};this.setFocus=function(){D.isFocused=!0;s.trigger()};this.removeFocus=function(){D.isFocused=!1;s.trigger()};this.show=function(){D.isShown=!0;s.trigger()};this.hide=function(){D.isShown=
!1;s.trigger()};this.setAvatarImageUrl=function(b){d.setImageUrl(b)};this.setColor=function(b){h.style.borderColor=b;d.setColor(b)};this.getCursor=function(){return f};this.getFocusElement=function(){return h};this.toggleHandleVisibility=function(){d.isVisible()?d.hide():d.show()};this.showHandle=function(){d.show()};this.hideHandle=function(){d.hide()};this.setOverlayElement=function(a){b=a;g.appendChild(a);H=!0;s.trigger()};this.ensureVisible=function(){C=!0;s.trigger()};this.getBoundingClientRect=
function(){return t.getBoundingClientRect(g)};this.destroy=function(b){core.Async.destroyAll([s.destroy,x.destroy,d.destroy,q],b)};(function(){var b=f.getDocument(),e=[b.createRootFilter(f.getMemberId()),b.getPositionFilter()],m=b.getDOMDocument();l=m.createRange();r=m.createElement("span");r.className="webodf-caretSizer";r.textContent="|";f.getNode().appendChild(r);g=m.createElement("div");g.setAttributeNS("urn:webodf:names:editinfo","editinfo:memberid",f.getMemberId());g.className="webodf-caretOverlay";
h=m.createElement("div");h.className="caret";g.appendChild(h);d=new gui.Avatar(g,a);y.getSizer().appendChild(g);w=b.createStepIterator(f.getNode(),0,e,b.getRootNode());s=core.Task.createRedrawTask(p);x=core.Task.createTimeoutTask(c,500);s.triggerImmediate()})()};odf.TextSerializer=function(){function f(e){var c="",m=k.filter?k.filter.acceptNode(e):NodeFilter.FILTER_ACCEPT,n=e.nodeType,p;if((m===NodeFilter.FILTER_ACCEPT||m===NodeFilter.FILTER_SKIP)&&a.isTextContentContainingNode(e))for(p=e.firstChild;p;)c+=f(p),p=p.nextSibling;m===NodeFilter.FILTER_ACCEPT&&(n===Node.ELEMENT_NODE&&a.isParagraph(e)?c+="\n":n===Node.TEXT_NODE&&e.textContent&&(c+=e.textContent));return c}var k=this,a=odf.OdfUtils;this.filter=null;this.writeToString=function(a){if(!a)return"";