Vergleich jscripts/sceditor/plugins/undo.js - 1.8.21 - 1.8.35

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 1Zeile 1
/* SCEditor v2.1.3 | (C) 2017, Sam Clarke | sceditor.com/license */

/* SCEditor v3.1.1 | (C) 2017, Sam Clarke | sceditor.com/license */





!function(e){"use strict";sceditor.plugins.undo=function(){var r,o,e=this,u=0,a=50,n=[],c=[],s=!1,l=function(e){s=!0,o=e.value,r.sourceMode(e.sourceMode),r.val(e.value,!1),r.focus(),e.sourceMode?r.sourceEditorCaret(e.caret):r.getRangeHelper().restoreRange(),s=!1};e.init=function(){a=(r=this).undoLimit||a,r.addShortcut("ctrl+z",e.undo),r.addShortcut("ctrl+shift+z",e.redo),r.addShortcut("ctrl+y",e.redo)},e.undo=function(){var e=c.pop(),t=r.val(null,!1);return e&&!n.length&&t===e.value&&(e=c.pop()),e&&(n.length||n.push({caret:r.sourceEditorCaret(),sourceMode:r.sourceMode(),value:t}),n.push(e),l(e)),!1},e.redo=function(){var e=n.pop();return c.length||(c.push(e),e=n.pop()),e&&(c.push(e),l(e)),!1},e.signalReady=function(){var e=r.val(null,!1);o=e,c.push({caret:this.sourceEditorCaret(),sourceMode:this.sourceMode(),value:e})},e.signalValuechangedEvent=function(e){var t=e.detail.rawValue;0<a&&c.length>a&&c.shift(),!s&&o&&o!==t&&(n.length=0,(u+=function(e,t){var r,o,u,a,n=e.length,c=t.length,s=Math.max(n,c);for(r=0;r<s&&e.charAt(r)===t.charAt(r);r++);for(u=n<c?c-n:0,a=c<n?n-c:0,o=s-1;0<=o&&e.charAt(o-u)===t.charAt(o-a);o--);return o-r+1}(o,t))<20||u<50&&!/\s$/g.test(e.rawValue)||(c.push({caret:r.sourceEditorCaret(),sourceMode:r.sourceMode(),value:t}),u=0,o=t))}}}();

!function(){"use strict";sceditor.plugins.undo=function(){var n,o,r,i,a=this,s="",c=0,u=!1,d=!1,l=!1,e=50,t=[],g=0;function f(e){var t;d=!0,o.sourceMode(e.sourceMode),e.sourceMode?(o.val(e.value,!1),o.sourceEditorCaret(e.caret)):(o.getBody().innerHTML=e.value,function(e,t){try{var n=t.startPositions,o=t.endPositions;e.setStart(S(r,n),n[0]),e.setEnd(S(r,o),o[0])}catch(e){console&&console.warn&&console.warn("[SCEditor] Undo plugin lost caret",e)}}(t=o.getRangeHelper().selectedRange(),e.caret),o.getRangeHelper().selectRange(t)),o.focus(),d=!1}function p(e,t){var n=e[t];e[t]=function(){var e=u;!e&&!d&&i&&o.getRangeHelper().hasSelection()&&h(),u=!0,n.apply(this,arguments),e||(u=!1,d||(v(),s=""))}}function v(){g&&(t.length-=g,g=0),0<e&&t.length>e&&t.shift(),i={},h(),t.push(i)}function h(){var e,t=o.sourceMode();i.caret=t?o.sourceEditorCaret():(e=o.getRangeHelper().selectedRange(),r.normalize(),{startPositions:y(e.startContainer,e.startOffset),endPositions:y(e.endContainer,e.endOffset)}),i.sourceMode=t,i.value=t?o.getSourceEditorValue(!1):o.getBody().innerHTML}function E(){n===document.activeElement&&a.signalSelectionchangedEvent()}function y(e,t){for(var n=[t],o=e;o&&"BODY"!==o.tagName;)n.push(function(e){var t=0;for(;e=e.previousSibling;)t++;return t}(o)),o=o.parentNode;return n}function S(e,t){for(var n=t.length-1;e&&0<n;n--)e=e.childNodes[t[n]];return e}a.init=function(){e=(o=this).undoLimit||e,o.addShortcut("ctrl+z",a.undo),o.addShortcut("ctrl+shift+z",a.redo),o.addShortcut("ctrl+y",a.redo)},a.signalReady=function(){function e(e){"historyUndo"===e.inputType?(a.undo(),e.preventDefault()):"historyRedo"===e.inputType&&(a.redo(),e.preventDefault())}function t(){s="",v()}n=o.getContentAreaContainer().nextSibling,r=o.getBody(),v(),p(o,"setWysiwygEditorValue"),p(o,"setSourceEditorValue"),p(o,"sourceEditorInsertText"),p(o.getRangeHelper(),"insertNode"),p(o,"toggleSourceMode"),r.addEventListener("beforeinput",e),n.addEventListener("beforeinput",e),r.addEventListener("compositionend",t),n.addEventListener("compositionend",t),document.addEventListener("selectionchange",E)},a.destroy=function(){document.removeEventListener("selectionchange",E)},a.undo=function(){return i=null,g<t.length-1&&(g++,f(t[t.length-1-g])),!1},a.redo=function(){return 0<g&&(g--,f(t[t.length-1-g])),!1},a.signalSelectionchangedEvent=function(){d||l?l=!1:(i&&h(),s="")},a.signalInputEvent=function(e){var t=e.inputType;if(l=!0,t&&!e.isComposing)switch(e.inputType){case"deleteContentBackward":i&&s===t&&c<20?h():(v(),c=0),s=t;break;case"insertText":c+=e.data?e.data.length:1,i&&s===t&&c<20&&!/\s$/.test(e.data)?h():(v(),c=0),s=t;break;default:s="sce-misc",c=0,v()}}}}();