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