Files
leanote/public/libs/ace/ck/ext-whitespace-min.js
2015-03-31 14:27:26 +08:00

1 line
2.3 KiB
JavaScript

ace.define("ace/ext/whitespace",["require","exports","module","ace/lib/lang"],function(e,t,n){"use strict";var r=e("../lib/lang");t.$detectIndentation=function(e,t){function n(e){for(var t=0,n=e;n<r.length;n+=e)t+=r[n]||0;return t}for(var r=[],i=[],a=0,s=0,c=Math.min(e.length,1e3),o=0;c>o;o++){var g=e[o];if(/^\s*[^*+\-\s]/.test(g)){" "==g[0]&&a++;var h=g.match(/^ */)[0].length;if(h&&" "!=g[h]){var l=h-s;l>0&&!(s%l)&&!(h%l)&&(i[l]=(i[l]||0)+1),r[h]=(r[h]||0)+1}for(s=h;c>o&&"\\"==g[g.length-1];)g=e[o++]}}for(var f=i.reduce(function(e,t){return e+t},0),u={score:0,length:0},v=0,o=1;12>o;o++){var d=n(o);1==o?(v=d,d=r[1]?.9:.8,r.length||(d=0)):d/=v,i[o]&&(d+=i[o]/f),d>u.score&&(u={score:d,length:o})}if(u.score&&u.score>1.4)var m=u.length;return a>v+1?{ch:" ",length:m}:v>a+1?{ch:" ",length:m}:void 0},t.detectIndentation=function(e){var n=e.getLines(0,1e3),r=t.$detectIndentation(n)||{};return r.ch&&e.setUseSoftTabs(" "==r.ch),r.length&&e.setTabSize(r.length),r},t.trimTrailingSpace=function(e,t){for(var n=e.getDocument(),r=n.getAllLines(),i=t?-1:0,a=0,s=r.length;s>a;a++){var c=r[a],o=c.search(/\s+$/);o>i&&n.removeInLine(a,o,c.length)}},t.convertIndentation=function(e,t,n){var i=e.getTabString()[0],a=e.getTabSize();n||(n=a),t||(t=i);for(var s=" "==t?t:r.stringRepeat(t,n),c=e.doc,o=c.getAllLines(),g={},h={},l=0,f=o.length;f>l;l++){var u=o[l],v=u.match(/^\s*/)[0];if(v){var d=e.$getStringScreenWidth(v)[0],m=Math.floor(d/a),p=d%a,S=g[m]||(g[m]=r.stringRepeat(s,m));S+=h[p]||(h[p]=r.stringRepeat(" ",p)),S!=v&&(c.removeInLine(l,0,v.length),c.insertInLine({row:l,column:0},S))}}e.setTabSize(n),e.setUseSoftTabs(" "==t)},t.$parseStringArg=function(e){var t={};/t/.test(e)?t.ch=" ":/s/.test(e)&&(t.ch=" ");var n=e.match(/\d+/);return n&&(t.length=parseInt(n[0],10)),t},t.$parseArg=function(e){return e?"string"==typeof e?t.$parseStringArg(e):"string"==typeof e.text?t.$parseStringArg(e.text):e:{}},t.commands=[{name:"detectIndentation",exec:function(e){t.detectIndentation(e.session)}},{name:"trimTrailingSpace",exec:function(e){t.trimTrailingSpace(e.session)}},{name:"convertIndentation",exec:function(e,n){var r=t.$parseArg(n);t.convertIndentation(e.session,r.ch,r.length)}},{name:"setIndentation",exec:function(e,n){var r=t.$parseArg(n);r.length&&e.session.setTabSize(r.length),r.ch&&e.session.setUseSoftTabs(" "==r.ch)}}]}),function(){ace.require(["ace/ext/whitespace"],function(){})}();