ace.define("ace/ext/elastic_tabstops_lite",["require","exports","module","ace/editor","ace/config"],function(v,d,x){"use strict";var g=function(){function u(e){this.$editor=e;var r=this,o=[],t=!1;this.onAfterExec=function(){t=!1,r.processRows(o),o=[]},this.onExec=function(){t=!0},this.onChange=function(s){t&&(-1==o.indexOf(s.start.row)&&o.push(s.start.row),s.end.row!=s.start.row&&o.push(s.end.row))}}return u.prototype.processRows=function(e){this.$inChange=!0;for(var r=[],o=0,t=e.length;o<t;o++){var s=e[o];if(!(r.indexOf(s)>-1))for(var i=this.$findCellWidthsForBlock(s),n=this.$setBlockCellWidthsToMax(i.cellWidths),h=i.firstRow,c=0,a=n.length;c<a;c++){var l=n[c];r.push(h),this.$adjustRow(h,l),h++}}this.$inChange=!1},u.prototype.$findCellWidthsForBlock=function(e){for(var o,r=[],t=e;t>=0&&0!=(o=this.$cellWidthsForRow(t)).length;)r.unshift(o),t--;var s=t+1;t=e;for(var i=this.$editor.session.getLength();t<i-1&&(t++,0!=(o=this.$cellWidthsForRow(t)).length);)r.push(o);return{cellWidths:r,firstRow:s}},u.prototype.$cellWidthsForRow=function(e){for(var r=this.$selectionColumnsForRow(e),o=[-1].concat(this.$tabsForRow(e)),t=o.map(function(p){return 0}).slice(1),s=this.$editor.session.getLine(e),i=0,n=o.length-1;i<n;i++){var h=o[i]+1,c=o[i+1],a=this.$rightmostSelectionInCell(r,c),l=s.substring(h,c);t[i]=Math.max(l.replace(/\s+$/g,"").length,a-h)}return t},u.prototype.$selectionColumnsForRow=function(e){var r=[],o=this.$editor.getCursorPosition();return this.$editor.session.getSelection().isEmpty()&&e==o.row&&r.push(o.column),r},u.prototype.$setBlockCellWidthsToMax=function(e){for(var o,t,s,r=!0,i=this.$izip_longest(e),n=0,h=i.length;n<h;n++){var c=i[n];if(c.push){c.push(NaN);for(var a=0,l=c.length;a<l;a++){var p=c[a];if(r&&(o=a,s=0,r=!1),isNaN(p)){t=a;for(var f=o;f<t;f++)e[f][n]=s;r=!0}s=Math.max(s,p)}}else console.error(c)}return e},u.prototype.$rightmostSelectionInCell=function(e,r){var o=0;if(e.length){for(var t=[],s=0,i=e.length;s<i;s++)t.push(e[s]<=r?s:0);o=Math.max.apply(Math,t)}return o},u.prototype.$tabsForRow=function(e){for(var s,r=[],o=this.$editor.session.getLine(e),t=/\t/g;null!=(s=t.exec(o));)r.push(s.index);return r},u.prototype.$adjustRow=function(e,r){var o=this.$tabsForRow(e);if(0!=o.length)for(var t=0,s=-1,i=this.$izip(r,o),n=0,h=i.length;n<h;n++){var a=i[n][1],l=(s+=1+i[n][0])-(a+=t);if(0!=l){var p=this.$editor.session.getLine(e).substr(0,a),f=p.replace(/\s*$/g,""),m=p.length-f.length;l>0&&(this.$editor.session.getDocument().insertInLine({row:e,column:a+1},Array(l+1).join(" ")+"\t"),this.$editor.session.getDocument().removeInLine(e,a,a+1),t+=l),l<0&&m>=-l&&(this.$editor.session.getDocument().removeInLine(e,a+l,a),t+=l)}}},u.prototype.$izip_longest=function(e){if(!e[0])return[];for(var r=e[0].length,o=e.length,t=1;t<o;t++){var s=e[t].length;s>r&&(r=s)}for(var i=[],n=0;n<r;n++){var h=[];for(t=0;t<o;t++)h.push(""===e[t][n]?NaN:e[t][n]);i.push(h)}return i},u.prototype.$izip=function(e,r){for(var o=e.length>=r.length?r.length:e.length,t=[],s=0;s<o;s++)t.push([e[s],r[s]]);return t},u}();d.ElasticTabstopsLite=g;var $=v("../editor").Editor;v("../config").defineOptions($.prototype,"editor",{useElasticTabstops:{set:function(u){u?(this.elasticTabstops||(this.elasticTabstops=new g(this)),this.commands.on("afterExec",this.elasticTabstops.onAfterExec),this.commands.on("exec",this.elasticTabstops.onExec),this.on("change",this.elasticTabstops.onChange)):this.elasticTabstops&&(this.commands.removeListener("afterExec",this.elasticTabstops.onAfterExec),this.commands.removeListener("exec",this.elasticTabstops.onExec),this.removeListener("change",this.elasticTabstops.onChange))}}})}),ace.require(["ace/ext/elastic_tabstops_lite"],function(v){"object"==typeof module&&"object"==typeof exports&&module&&(module.exports=v)});