/* SCEditor v1.4.5 | (C) 2011-2014, Sam Clarke | sceditor.com/license */
(function(e){"use strict";e.sceditor.plugins.undo=function(){var e=this;var t;var n=0;var r;var i=50;var s=[];var o=[];var u=false;var a=function(e){u=true;r=e.value;t.sourceMode(e.sourceMode);t.val(e.value,false);t.focus();if(e.sourceMode){t.sourceEditorCaret(e.caret)}else{t.getRangeHelper().restoreRange()}u=false};var f=function(e,t){var n,r,i,s,o=e.length,u=t.length,a=Math.max(o,u);for(n=0;n<a;n++){if(e[n]!==t[n]){break}}i=o<u?u-o:0;s=u<o?o-u:0;for(r=a-1;r>=0;r--){if(e[r-i]!==t[r-s]){break}}return r-n+1};e.init=function(){t=this;i=t.undoLimit||i;t.addShortcut("ctrl+z",e.undo);t.addShortcut("ctrl+shift+z",e.redo);t.addShortcut("ctrl+y",e.redo)};e.undo=function(){var e=o.pop();var n=t.val(null,false);if(e&&!s.length&&n===e.value){e=o.pop()}if(e){if(!s.length){s.push({caret:t.sourceEditorCaret(),sourceMode:t.sourceMode(),value:n})}s.push(e);a(e)}return false};e.redo=function(){var e=s.pop();if(!o.length){o.push(e);e=s.pop()}if(e){o.push(e);a(e)}return false};e.signalReady=function(){var e=t.val(null,false);r=e;o.push({caret:this.sourceEditorCaret(),sourceMode:this.sourceMode(),value:e})};e.signalValuechangedEvent=function(e){var a=e.rawValue;if(i>0&&o.length>i){o.shift()}if(u||r===a){return}s.length=0;n+=f(r,a);if(n<20){return}else if(n<50&&!e.rawValue[e.rawValue.length-1].match(/\s/g)){return}o.push({caret:t.sourceEditorCaret(),sourceMode:t.sourceMode(),value:a});n=0;r=a}}})(jQuery)