Skip to content

Commit

Permalink
fixed autointent for multiple , in a row
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbtn committed Oct 25, 2012
1 parent 5c0338b commit ef86234
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 40 deletions.
16 changes: 13 additions & 3 deletions excelFormulaUtilities-0.9.4.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@
function applyTokenTemplate(token, options, indent, lineBreak, override) {

var indt = indent;

var lastToken = typeof arguments[5] === undefined || arguments[5] === null ? null : arguments[5];

var replaceTokenTmpl = function (inStr) {
return inStr.replace(/\{\{token\}\}/gi, "{0}").replace(/\{\{autoindent\}\}/gi, "{1}").replace(/\{\{autolinebreak\}\}/gi, "{2}");
Expand Down Expand Up @@ -938,7 +940,11 @@
tokenString = formatStr(replaceTokenTmpl(options.tmplOperandLogical), tokenString, indt, lineBreak);
break;
case "argument":
tokenString = formatStr(replaceTokenTmpl(options.tmplArgument), tokenString, indt, lineBreak);
if(lastToken.type !== "argument"){
tokenString = formatStr(replaceTokenTmpl(options.tmplArgument), tokenString, indt, lineBreak);
} else {
tokenString = formatStr(replaceTokenTmpl("{{autoindent}}"+options.tmplArgument), tokenString, indt, lineBreak);
}
break;
case "subexpression":
if (token.subtype.toString() === "start") {
Expand Down Expand Up @@ -1063,7 +1069,9 @@
}
return false;
};


var lastToken = null;

while (tokens.moveNext()) {

var token = tokens.current();
Expand All @@ -1080,7 +1088,7 @@
indt = autoIndent ? indent() : options.tmplIndentSpace,
lineBreak = autoBreak ? options.newLine : "";

outputFormula += applyTokenTemplate(token, options, indt, lineBreak, options.customTokenRender);
outputFormula += applyTokenTemplate(token, options, indt, lineBreak, options.customTokenRender, lastToken);

if (token.subtype.toString() === TOK_SUBTYPE_START) {
indentCount += 1;
Expand All @@ -1089,6 +1097,8 @@

isNewLine = autoBreak || matchEndNewLine.test(outputFormula);
isFirstToken = false;

lastToken = token;
}

outputFormula = options.prefix + trim(outputFormula) + options.postfix;
Expand Down
Loading

0 comments on commit ef86234

Please sign in to comment.