From 6cebecf437f563ffafe1448a9977ab6a1ec301f3 Mon Sep 17 00:00:00 2001 From: GoshaZotov Date: Thu, 7 Apr 2022 18:02:50 +0300 Subject: [PATCH 1/7] [se] Open wizard with data --- cell/model/FormulaObjects/parserFormula.js | 12 ++++++++++++ cell/view/WorkbookView.js | 17 ++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cell/model/FormulaObjects/parserFormula.js b/cell/model/FormulaObjects/parserFormula.js index 6d69df7fba..220a1d4084 100644 --- a/cell/model/FormulaObjects/parserFormula.js +++ b/cell/model/FormulaObjects/parserFormula.js @@ -5229,6 +5229,18 @@ _func[cElementType.cell3D] = _func[cElementType.cell]; return null; }; + ParseResult.prototype.getArgumentsValue = function(sFormula) { + var res = null; + if (sFormula && this.argPosArr) { + for (var i = 0; i < this.argPosArr.length; i++) { + if (!res) { + res = []; + } + res.push(sFormula.substring(this.argPosArr[i].start - 1, this.argPosArr[i].end - 1)); + } + } + return res; + }; var g_defParseResult = new ParseResult(undefined, undefined); diff --git a/cell/view/WorkbookView.js b/cell/view/WorkbookView.js index d3fa2dfe65..4af0dbd289 100644 --- a/cell/view/WorkbookView.js +++ b/cell/view/WorkbookView.js @@ -2585,9 +2585,24 @@ t.cellEditor.selectionBegin = 0; t.cellEditor.selectionEnd = t.cellEditor.textRender.getEndOfText(); } - t.cellEditor.insertFormula(name); + + var parseResult; + if (!name && t.cellEditor._formula) { + t.cellEditor._formula.isParsed = false; + parseResult = new AscCommonExcel.ParseResult([]); + t.cellEditor._formula.parse(undefined, undefined, parseResult, true); + name = parseResult.activeFunction.func.name; + } else { + t.cellEditor.insertFormula(name); + } + // ToDo send info from selection var res = name ? new AscCommonExcel.CFunctionInfo(name) : null; + if (res && parseResult) { + res.argumentsValue = parseResult.getArgumentsValue(t.cellEditor._formula.Formula); + } + + t.handlers.trigger("asc_onSendFunctionWizardInfo", res); }; From b23b367945f56b19d7d28c2ff71171702d753ba5 Mon Sep 17 00:00:00 2001 From: GoshaZotov Date: Thu, 7 Apr 2022 23:16:09 +0300 Subject: [PATCH 2/7] [se] Wizard --- cell/view/WorkbookView.js | 62 ++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/cell/view/WorkbookView.js b/cell/view/WorkbookView.js index 4af0dbd289..16248acaf1 100644 --- a/cell/view/WorkbookView.js +++ b/cell/view/WorkbookView.js @@ -2579,6 +2579,7 @@ } }; + var ws = this.getActiveWS(); var addFunction = function (name) { t.setWizardMode(true); if (doCleanCellContent || !t.cellEditor.isFormula()) { @@ -2586,23 +2587,64 @@ t.cellEditor.selectionEnd = t.cellEditor.textRender.getEndOfText(); } - var parseResult; - if (!name && t.cellEditor._formula) { - t.cellEditor._formula.isParsed = false; - parseResult = new AscCommonExcel.ParseResult([]); - t.cellEditor._formula.parse(undefined, undefined, parseResult, true); + var res; + if (!name && t.cellEditor._formula && t.cellEditor._parseResult) { + + //get arguments position + first function info(on open wizard) + /*t.cellEditor._formula.isParsed = false; + var parseResult = new AscCommonExcel.ParseResult([]); + t.cellEditor._formula.parse(undefined, undefined, parseResult, true);*/ + + var parseResult = t.cellEditor._parseResult; name = parseResult.activeFunction.func.name; + + if (name) { + res = new AscCommonExcel.CFunctionInfo(name) + + res.argumentsValue = parseResult.getArgumentsValue(t.cellEditor._formula.Formula); + if (res.argumentsValue) { + var argumentsType = parseResult.activeFunction.func.argumentsType; + res.argumentsResult = []; + for (var i = 0; i < res.argumentsValue.length; i++) { + var argType = null; + if (argumentsType) { + if (typeof argumentsType[i] == 'object') { + argType = argumentsType[i][0]; + } else if (i > argumentsType.length - 1) { + var lastArgType = argumentsType[argumentsType.length - 1]; + if (typeof lastArgType == 'object') { + argType = lastArgType[(i - (argumentsType.length - 1)) % lastArgType.length] + } + } else { + argType = argumentsType[i]; + } + } + var argCalc = ws.calculateWizardFormula(res.argumentsValue[i], argType); + res.argumentsResult[i] = argCalc.str; + } + } + + //get result + var sArguments = res.argumentsValue.join(AscCommon.FormulaSeparators.functionArgumentSeparator); + if (argCalc.obj && argCalc.obj.type !== AscCommonExcel.cElementType.error) { + var funcCalc = ws.calculateWizardFormula(name + '(' + sArguments + ')'); + res.functionResult = funcCalc.str; + if (funcCalc.obj && funcCalc.obj.type !== AscCommonExcel.cElementType.error) { + res.formulaResult = ws.calculateWizardFormula(t.cellEditor._formula).str; + } + } + + t.cellEditor.lastRangePos = parseResult.argPosArr[0].start; + t.cellEditor.lastRangeLength = parseResult.argPosArr[parseResult.argPosArr.length - 1].end - parseResult.argPosArr[0].start; + } } else { t.cellEditor.insertFormula(name); } // ToDo send info from selection - var res = name ? new AscCommonExcel.CFunctionInfo(name) : null; - if (res && parseResult) { - res.argumentsValue = parseResult.getArgumentsValue(t.cellEditor._formula.Formula); + if (!res) { + res = name ? new AscCommonExcel.CFunctionInfo(name) : null; } - - t.handlers.trigger("asc_onSendFunctionWizardInfo", res); }; From 2d03e79eb48eb9d300ec11d18220533454f6ab06 Mon Sep 17 00:00:00 2001 From: GoshaZotov Date: Fri, 8 Apr 2022 10:40:33 +0300 Subject: [PATCH 3/7] [se] By previous --- cell/view/WorkbookView.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/cell/view/WorkbookView.js b/cell/view/WorkbookView.js index 16248acaf1..101f61ef5a 100644 --- a/cell/view/WorkbookView.js +++ b/cell/view/WorkbookView.js @@ -2589,14 +2589,8 @@ var res; if (!name && t.cellEditor._formula && t.cellEditor._parseResult) { - - //get arguments position + first function info(on open wizard) - /*t.cellEditor._formula.isParsed = false; - var parseResult = new AscCommonExcel.ParseResult([]); - t.cellEditor._formula.parse(undefined, undefined, parseResult, true);*/ - var parseResult = t.cellEditor._parseResult; - name = parseResult.activeFunction.func.name; + name = parseResult.activeFunction && parseResult.activeFunction.func && parseResult.activeFunction.func.name; if (name) { res = new AscCommonExcel.CFunctionInfo(name) From ff3b914d8797749338d9913ed7e1092e80c3967a Mon Sep 17 00:00:00 2001 From: GoshaZotov Date: Fri, 8 Apr 2022 11:03:42 +0300 Subject: [PATCH 4/7] [se] Refactoring --- cell/model/FormulaObjects/parserFormula.js | 127 ++++++++++----------- 1 file changed, 59 insertions(+), 68 deletions(-) diff --git a/cell/model/FormulaObjects/parserFormula.js b/cell/model/FormulaObjects/parserFormula.js index 220a1d4084..f453aab799 100644 --- a/cell/model/FormulaObjects/parserFormula.js +++ b/cell/model/FormulaObjects/parserFormula.js @@ -5828,7 +5828,7 @@ function parserFormula( formula, parent, _ws ) { referenceCount += weight; if (referenceCount > AscCommon.c_oAscMaxFormulaReferenceLength) { parseResult.setError(c_oAscError.ID.FrmlMaxReference); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -5836,7 +5836,7 @@ function parserFormula( formula, parent, _ws ) { return true; }; - var parseOperators = function(){ + var parseOperators = function () { wasLeftParentheses = false; wasRigthParentheses = false; var found_operator = null; @@ -5875,7 +5875,7 @@ function parserFormula( formula, parent, _ws ) { found_operator = cFormulaOperators[ph.operand_str].prototype; parseResult.operand_expected = true; } else { - if(ignoreErrors) { + if (ignoreErrors) { return true; } else { parseResult.setError(c_oAscError.ID.FrmlWrongOperator); @@ -5886,11 +5886,8 @@ function parserFormula( formula, parent, _ws ) { } } - while (0 !== elemArr.length && ( - found_operator.rightAssociative ? - ( found_operator.priority < elemArr[elemArr.length - 1].priority ) : - ( found_operator.priority <= elemArr[elemArr.length - 1].priority ) - )) { + while (0 !== elemArr.length && (found_operator.rightAssociative ? (found_operator.priority < elemArr[elemArr.length - 1].priority) : + (found_operator.priority <= elemArr[elemArr.length - 1].priority))) { t.outStack.push(elemArr.pop()); } elemArr.push(found_operator); @@ -5899,7 +5896,7 @@ function parserFormula( formula, parent, _ws ) { return true; }; - var parseLeftParentheses = function(){ + var parseLeftParentheses = function () { if (wasRigthParentheses || found_operand) { elemArr.push(new cMultOperator()); } @@ -5912,9 +5909,9 @@ function parserFormula( formula, parent, _ws ) { leftParentArgumentsCurrentArr[elemArr.length - 1] = 1; parseResult.argPos = 1; - if(startSumproduct){ + if (startSumproduct) { counterSumproduct++; - if(1 === counterSumproduct){ + if (1 === counterSumproduct) { t.outStack.push(cSpecialOperandStart.prototype); } } @@ -5923,14 +5920,13 @@ function parserFormula( formula, parent, _ws ) { argPosArrMap[currentFuncLevel] = [{start: ph.pCurrPos + 1}]; }; - var parseRightParentheses = function(){ + var parseRightParentheses = function () { parseResult.addElem(cFormulaOperators[ph.operand_str].prototype); wasRigthParentheses = true; var top_elem = null; var top_elem_arg_count = 0; - if (0 !== elemArr.length && ( (top_elem = elemArr[elemArr.length - 1]).name === '(' ) && - parseResult.operand_expected) { + if (0 !== elemArr.length && ((top_elem = elemArr[elemArr.length - 1]).name === '(') && parseResult.operand_expected) { top_elem_arg_count = leftParentArgumentsCurrentArr[elemArr.length - 1]; if (top_elem_arg_count > 1) { t.outStack.push(new cEmpty()); @@ -5939,8 +5935,7 @@ function parserFormula( formula, parent, _ws ) { top_elem_arg_count = leftParentArgumentsCurrentArr[elemArr.length - 1]; } } else { - while (0 !== elemArr.length && - !((top_elem = elemArr[elemArr.length - 1]).name === '(' )) { + while (0 !== elemArr.length && !((top_elem = elemArr[elemArr.length - 1]).name === '(')) { if (top_elem.name in cFormulaOperators && parseResult.operand_expected) { parseResult.setError(c_oAscError.ID.FrmlOperandExpected); t.outStack = []; @@ -5953,7 +5948,7 @@ function parserFormula( formula, parent, _ws ) { if ((0 === elemArr.length || null === top_elem)) { parseResult.setError(c_oAscError.ID.FrmlWrongCountParentheses); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -5961,17 +5956,17 @@ function parserFormula( formula, parent, _ws ) { var p = top_elem, func, bError = false; elemArr.pop(); - if (0 !== elemArr.length && ( func = elemArr[elemArr.length - 1] ).type === cElementType.func) { + if (0 !== elemArr.length && (func = elemArr[elemArr.length - 1]).type === cElementType.func) { p = elemArr.pop(); if (top_elem_arg_count > func.argumentsMax) { parseResult.setError(c_oAscError.ID.FrmlWrongMaxArgument); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } } else { if (top_elem_arg_count >= func.argumentsMin) { - t.outStack.push(null !== startArrayArg && startArrayArg < currentFuncLevel ? - top_elem_arg_count : top_elem_arg_count); + t.outStack.push(null !== startArrayArg && startArrayArg < currentFuncLevel ? -top_elem_arg_count : top_elem_arg_count); if (!func.checkArguments(top_elem_arg_count)) { bError = true; } @@ -5981,24 +5976,24 @@ function parserFormula( formula, parent, _ws ) { if (bError) { parseResult.setError(c_oAscError.ID.FrmlWrongCountArgument); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } } } parseResult.argPos = leftParentArgumentsCurrentArr[elemArr.length - 1]; - } else if(wasLeftParentheses && 0 === top_elem_arg_count && elemArr[elemArr.length - 1] /*&& " " === elemArr[elemArr.length - 1].name*/) { + } else if (wasLeftParentheses && 0 === top_elem_arg_count && elemArr[elemArr.length - 1] /*&& " " === elemArr[elemArr.length - 1].name*/) { //intersection with empty range parseResult.setError(c_oAscError.ID.FrmlAnotherParsingError); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } } else { if (wasLeftParentheses && (!elemArr[elemArr.length - 1] || '(' === elemArr[elemArr.length - 1].name)) { parseResult.setError(c_oAscError.ID.FrmlAnotherParsingError); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -6012,9 +6007,9 @@ function parserFormula( formula, parent, _ws ) { parseResult.operand_expected = false; wasLeftParentheses = false; - if(startSumproduct){ + if (startSumproduct) { counterSumproduct--; - if(counterSumproduct < 1){ + if (counterSumproduct < 1) { startSumproduct = false; t.outStack.push(cSpecialOperandEnd.prototype); } @@ -6022,7 +6017,7 @@ function parserFormula( formula, parent, _ws ) { if (func && func.type === cElementType.func) { if (needCalcArgPos) { - if(needFuncLevel > 0) { + if (needFuncLevel > 0) { needFuncLevel--; } if (!parseResult.activeFunction && levelFuncMap[currentFuncLevel] && levelFuncMap[currentFuncLevel].startPos <= activePos && activePos <= ph.pCurrPos) { @@ -6040,15 +6035,15 @@ function parserFormula( formula, parent, _ws ) { return true; }; - var parseCommaAndArgumentsUnion = function(){ + var parseCommaAndArgumentsUnion = function () { wasLeftParentheses = false; wasRigthParentheses = false; var stackLength = elemArr.length, top_elem = null, top_elem_arg_pos; - if (elemArr.length !== 0 && elemArr[stackLength - 1].name === "(" && ((!elemArr[stackLength - 2]) || - (elemArr[stackLength - 2] && elemArr[stackLength - 2].type !== cElementType.func))) { + if (elemArr.length !== 0 && elemArr[stackLength - 1].name === "(" && + ((!elemArr[stackLength - 2]) || (elemArr[stackLength - 2] && elemArr[stackLength - 2].type !== cElementType.func))) { parseResult.setError(c_oAscError.ID.FrmlWrongOperator); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -6074,7 +6069,7 @@ function parserFormula( formula, parent, _ws ) { if (parseResult.operand_expected) { parseResult.setError(c_oAscError.ID.FrmlWrongOperator); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -6083,7 +6078,7 @@ function parserFormula( formula, parent, _ws ) { //TODO заглушка для парсинга множественного диапазона в _xlnm.Print_Area. необходимо сделать общий парсинг подобного содержимого if (!wasLeftParentheses && !(t.parent && t.parent instanceof window['AscCommonExcel'].DefName /*&& t.parent.name === "_xlnm.Print_Area"*/)) { parseResult.setError(c_oAscError.ID.FrmlWrongCountParentheses); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -6123,18 +6118,16 @@ function parserFormula( formula, parent, _ws ) { return true; }; - var parseArray = function(){ + var parseArray = function () { if (!_checkReferenceCount(2)) { return false; } wasLeftParentheses = false; wasRigthParentheses = false; var arr = new cArray(), operator = {isOperator: false, operatorName: ""}; - while (ph.pCurrPos < t.Formula.length && - !parserHelp.isRightBrace.call(ph, t.Formula, ph.pCurrPos)) { + while (ph.pCurrPos < t.Formula.length && !parserHelp.isRightBrace.call(ph, t.Formula, ph.pCurrPos)) { if (parserHelp.isArraySeparator.call(ph, t.Formula, ph.pCurrPos, digitDelim)) { - if (ph.operand_str === (digitDelim ? FormulaSeparators.arrayRowSeparator : - FormulaSeparators.arrayRowSeparatorDef)) { + if (ph.operand_str === (digitDelim ? FormulaSeparators.arrayRowSeparator : FormulaSeparators.arrayRowSeparatorDef)) { arr.addRow(); } } else if (parserHelp.isBoolean.call(ph, t.Formula, ph.pCurrPos, local)) { @@ -6204,7 +6197,7 @@ function parserFormula( formula, parent, _ws ) { if (!arr.isValidArray()) { /*размер массива не согласован*/ parseResult.setError(c_oAscError.ID.FrmlAnotherParsingError); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -6214,7 +6207,7 @@ function parserFormula( formula, parent, _ws ) { return true; }; - var parseOperands = function(){ + var parseOperands = function () { found_operand = null; if (wasRigthParentheses) { @@ -6223,7 +6216,7 @@ function parserFormula( formula, parent, _ws ) { if (!parseResult.operand_expected) { parseResult.setError(c_oAscError.ID.FrmlWrongOperator); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -6241,12 +6234,12 @@ function parserFormula( formula, parent, _ws ) { /* Strings */ else if (parserHelp.isString.call(ph, t.Formula, ph.pCurrPos)) { if (ph.operand_str.length > g_nFormulaStringMaxLength) { parseResult.setError(c_oAscError.ID.FrmlMaxTextLength); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } } - if (!_checkReferenceCount(ph.operand_str.length*0.25 + 0.5)) { + if (!_checkReferenceCount(ph.operand_str.length * 0.25 + 0.5)) { return false; } found_operand = new cString(ph.operand_str); @@ -6259,8 +6252,7 @@ function parserFormula( formula, parent, _ws ) { found_operand = new cError(ph.operand_str); } - /* Referens to 3D area: Sheet1:Sheet3!A1:B3, Sheet1:Sheet3!B3, Sheet1!B3*/ else if ((_3DRefTmp = - parserHelp.is3DRef.call(ph, t.Formula, ph.pCurrPos))[0]) { + /* Referens to 3D area: Sheet1:Sheet3!A1:B3, Sheet1:Sheet3!B3, Sheet1!B3*/ else if ((_3DRefTmp = parserHelp.is3DRef.call(ph, t.Formula, ph.pCurrPos))[0]) { t.is3D = true; @@ -6281,7 +6273,7 @@ function parserFormula( formula, parent, _ws ) { if (!(wsF && wsT)) { parseResult.setError(c_oAscError.ID.FrmlWrongReferences); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -6292,7 +6284,7 @@ function parserFormula( formula, parent, _ws ) { } if (parserHelp.isArea.call(ph, t.Formula, ph.pCurrPos)) { - if(!(wsF && wsT)) { + if (!(wsF && wsT)) { //for edit formula mode //found_operand = new cUnknownFunction(ph.real_str ? ph.real_str.toUpperCase() : ph.operand_str.toUpperCase()); found_operand = new cName(ph.real_str ? ph.real_str.toUpperCase() : ph.operand_str.toUpperCase(), t.ws); @@ -6301,7 +6293,7 @@ function parserFormula( formula, parent, _ws ) { } parseResult.addRefPos(prevCurrPos, ph.pCurrPos, t.outStack.length, found_operand); } else if (parserHelp.isRef.call(ph, t.Formula, ph.pCurrPos)) { - if(!(wsF && wsT)) { + if (!(wsF && wsT)) { //for edit formula mode //found_operand = new cUnknownFunction(ph.real_str ? ph.real_str.toUpperCase() : ph.operand_str.toUpperCase()); found_operand = new cName(ph.real_str ? ph.real_str.toUpperCase() : ph.operand_str.toUpperCase(), t.ws); @@ -6331,16 +6323,14 @@ function parserFormula( formula, parent, _ws ) { } found_operand = new cRef(ph.real_str ? ph.real_str.toUpperCase() : ph.operand_str.toUpperCase(), t.ws); parseResult.addRefPos(ph.pCurrPos - ph.operand_str.length, ph.pCurrPos, t.outStack.length, found_operand); - } - - else if (_tableTMP = parserHelp.isTable.call(ph, t.Formula, ph.pCurrPos, local)) { + } else if (_tableTMP = parserHelp.isTable.call(ph, t.Formula, ph.pCurrPos, local)) { found_operand = cStrucTable.prototype.createFromVal(_tableTMP, t.wb, t.ws, tablesMap); //todo undo delete column if (found_operand.type === cElementType.error) { /*используется неверный именованный диапазон или таблица*/ parseResult.setError(c_oAscError.ID.FrmlAnotherParsingError); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -6360,7 +6350,7 @@ function parserFormula( formula, parent, _ws ) { if (ph.operand_str.length > g_nFormulaStringMaxLength || !AscCommon.rx_r1c1DefError.test(ph.operand_str)) { //TODO стоит добавить новую ошибку parseResult.setError(c_oAscError.ID.FrmlWrongOperator); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -6374,12 +6364,12 @@ function parserFormula( formula, parent, _ws ) { var defName; var sDefNameOperand = ph.operand_str.replace(rx_sDefNamePref, ""); var tryTranslate = AscCommonExcel.tryTranslateToPrintArea(sDefNameOperand); - if(tryTranslate) { + if (tryTranslate) { found_operand = new cName(tryTranslate, t.ws); defName = found_operand.getDefName(); } //TODO возможно здесь нужно else ставить - if(!defName) { + if (!defName) { found_operand = new cName(sDefNameOperand, t.ws); defName = found_operand.getDefName(); } @@ -6402,7 +6392,7 @@ function parserFormula( formula, parent, _ws ) { found_operand = new cNumber(_number); } else { parseResult.setError(c_oAscError.ID.FrmlAnotherParsingError); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -6422,7 +6412,7 @@ function parserFormula( formula, parent, _ws ) { found_operator = cAllFormulaFunction[operandStr].prototype; } else { found_operator = new cUnknownFunction(operandStr); - found_operator.isXLFN = ( ph.operand_str.indexOf("_xlfn.") === 0 ); + found_operator.isXLFN = (ph.operand_str.indexOf("_xlfn.") === 0); } if (found_operator !== null) { @@ -6435,7 +6425,7 @@ function parserFormula( formula, parent, _ws ) { } elemArr.push(found_operator); parseResult.addElem(found_operator); - if("SUMPRODUCT" === found_operator.name){ + if ("SUMPRODUCT" === found_operator.name) { startSumproduct = true; } @@ -6460,7 +6450,7 @@ function parserFormula( formula, parent, _ws ) { } else { parseResult.setError(c_oAscError.ID.FrmlWrongFunctionName); - if(!ignoreErrors) { + if (!ignoreErrors) { t.outStack = []; return false; } @@ -6499,7 +6489,8 @@ function parserFormula( formula, parent, _ws ) { parseResult.activeFunction = {func: levelFuncMap[currentFuncLevel].func, start: levelFuncMap[currentFuncLevel].startPos, end: ph.pCurrPos + 1}; parseResult.argPosArr = argPosArrMap[currentFuncLevel]; } - if (undefined === parseResult.activeArgumentPos && argFuncMap[currentFuncLevel] && argFuncMap[currentFuncLevel].startPos <= activePos && activePos <= ph.pCurrPos + 1) { + if (undefined === parseResult.activeArgumentPos && argFuncMap[currentFuncLevel] && argFuncMap[currentFuncLevel].startPos <= activePos && activePos <= ph.pCurrPos + + 1) { parseResult.activeArgumentPos = argFuncMap[currentFuncLevel].count; } var _argPos = argPosArrMap[currentFuncLevel]; @@ -6513,14 +6504,14 @@ function parserFormula( formula, parent, _ws ) { ph.operand_str = this.Formula[ph.pCurrPos]; //TODO сделать так, чтобы добавлялся особый элемент - перенос строки и учитывался при сборке!!!! - if(ph.operand_str=="\n") { + if (ph.operand_str == "\n") { ph.pCurrPos++; continue; } /* Operators*/ if (parserHelp.isOperator.call(ph, this.Formula, ph.pCurrPos) || parserHelp.isNextPtg.call(ph, this.Formula, ph.pCurrPos)) { - if(!parseOperators()){ + if (!parseOperators()) { if (ignoreErrors) { setArgInfo(); } @@ -6531,35 +6522,35 @@ function parserFormula( formula, parent, _ws ) { //TODO протестировать //если осталось только закрыть скобки за функции с нулевым количеством аргументов - if(ph.pCurrPos === this.Formula.length){ - if(elemArr[elemArr.length - 2] && 0 === elemArr[elemArr.length - 2].argumentsMax){ + if (ph.pCurrPos === this.Formula.length) { + if (elemArr[elemArr.length - 2] && 0 === elemArr[elemArr.length - 2].argumentsMax) { parseResult.operand_expected = false; } } }/* Right Parentheses */ else if (parserHelp.isRightParentheses.call(ph, this.Formula, ph.pCurrPos)) { - if(!parseRightParentheses()){ + if (!parseRightParentheses()) { if (ignoreErrors) { setArgInfo(); } return false; } }/*Comma & arguments union*/ else if (parserHelp.isComma.call(ph, this.Formula, ph.pCurrPos)) { - if(!parseCommaAndArgumentsUnion()){ + if (!parseCommaAndArgumentsUnion()) { if (ignoreErrors) { setArgInfo(); } return false; } }/* Array */ else if (parserHelp.isLeftBrace.call(ph, this.Formula, ph.pCurrPos)) { - if(!parseArray()){ + if (!parseArray()) { if (ignoreErrors) { setArgInfo(); } return false; } }/* Operands*/ else { - if(!parseOperands()){ + if (!parseOperands()) { if (ignoreErrors) { setArgInfo(); } From 86f3ebaaa647f6a46bae01d7271b5c08e93129a8 Mon Sep 17 00:00:00 2001 From: GoshaZotov Date: Fri, 8 Apr 2022 15:16:24 +0300 Subject: [PATCH 5/7] [se] Wizard --- cell/model/FormulaObjects/parserFormula.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cell/model/FormulaObjects/parserFormula.js b/cell/model/FormulaObjects/parserFormula.js index f453aab799..6e56892176 100644 --- a/cell/model/FormulaObjects/parserFormula.js +++ b/cell/model/FormulaObjects/parserFormula.js @@ -6029,6 +6029,12 @@ function parserFormula( formula, parent, _ws ) { if (_argPos && _argPos[_argPos.length - 1] && undefined === _argPos[_argPos.length - 1].end) { _argPos[_argPos.length - 1].end = ph.pCurrPos; } + + if (!parseResult.allFunctionsPos) { + parseResult.allFunctionsPos = []; + } + parseResult.allFunctionsPos.push({func: levelFuncMap[currentFuncLevel].func, start: levelFuncMap[currentFuncLevel].startPos, end: ph.pCurrPos, args: _argPos}); + currentFuncLevel--; } @@ -6497,6 +6503,12 @@ function parserFormula( formula, parent, _ws ) { if (_argPos && _argPos[_argPos.length - 1] && undefined === _argPos[_argPos.length - 1].end) { _argPos[_argPos.length - 1].end = ph.pCurrPos; } + if (levelFuncMap[currentFuncLevel]) { + if (!parseResult.allFunctionsPos) { + parseResult.allFunctionsPos = []; + } + parseResult.allFunctionsPos.push({func: levelFuncMap[currentFuncLevel].func, start: levelFuncMap[currentFuncLevel].startPos, end: ph.pCurrPos, args: _argPos}); + } } }; From a5933fe68ba3a2fdb40710ae592f76d8cb9f6a69 Mon Sep 17 00:00:00 2001 From: GoshaZotov Date: Wed, 13 Apr 2022 11:37:25 +0300 Subject: [PATCH 6/7] [se] Get info about active function if edit cell --- cell/model/FormulaObjects/parserFormula.js | 53 ++++++++++++++++++++++ cell/view/WorkbookView.js | 16 ++++++- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/cell/model/FormulaObjects/parserFormula.js b/cell/model/FormulaObjects/parserFormula.js index 6e56892176..1edd20e23e 100644 --- a/cell/model/FormulaObjects/parserFormula.js +++ b/cell/model/FormulaObjects/parserFormula.js @@ -5242,6 +5242,59 @@ _func[cElementType.cell3D] = _func[cElementType.cell]; return res; }; + ParseResult.prototype.getActiveFunction = function(start, end) { + var res = null; + if (this.allFunctionsPos) { + var startFuncs, endFuncs, i, j; + for (i = 0; i < this.allFunctionsPos.length; i++) { + if (this.allFunctionsPos[i].start <= start && this.allFunctionsPos[i].end >= start) { + if (!startFuncs) { + startFuncs = []; + } + startFuncs.push(this.allFunctionsPos[i]); + } + if (start !== end && this.allFunctionsPos[i].start <= end && this.allFunctionsPos[i].end >= end) { + if (!endFuncs) { + endFuncs = []; + } + endFuncs.push(this.allFunctionsPos[i]); + } + } + + if (startFuncs) { + var commonFuncs; + if (start === end) { + commonFuncs = startFuncs; + } else if (endFuncs) { + //ищем самую внутреннюю функцию, где находится и начало и конец диапазона + for (i = 0; i < startFuncs.length; i++) { + for (j = 0; j < endFuncs.length; j++) { + if (startFuncs[i] === endFuncs[j]) { + if (!commonFuncs) { + commonFuncs = []; + } + commonFuncs.push(startFuncs[i]); + break; + } + } + } + } + + //ищем самую внутреннюю функцию + if (commonFuncs) { + res = commonFuncs[0]; + for (i = 1; i < commonFuncs.length; i++) { + if (commonFuncs[i].start >= res.start && commonFuncs[i].end <= res.end) { + res = commonFuncs[i]; + } + } + } + } + + } + return res; + }; + var g_defParseResult = new ParseResult(undefined, undefined); var lastListenerId = 0; diff --git a/cell/view/WorkbookView.js b/cell/view/WorkbookView.js index 101f61ef5a..41805e6580 100644 --- a/cell/view/WorkbookView.js +++ b/cell/view/WorkbookView.js @@ -2580,7 +2580,7 @@ }; var ws = this.getActiveWS(); - var addFunction = function (name) { + var addFunction = function (name, cellEditMode) { t.setWizardMode(true); if (doCleanCellContent || !t.cellEditor.isFormula()) { t.cellEditor.selectionBegin = 0; @@ -2592,9 +2592,20 @@ var parseResult = t.cellEditor._parseResult; name = parseResult.activeFunction && parseResult.activeFunction.func && parseResult.activeFunction.func.name; + if (cellEditMode) { + //ищем общую функцию, в которой находится курсор + //если начало и конец селекта в одной функции - показываем настройки для неё, если в разных - добавляем новую + var activeFunction = parseResult.getActiveFunction(t.cellEditor.selectionBegin, t.cellEditor.selectionEnd); + if (activeFunction) { + parseResult.activeFunction = activeFunction; + parseResult.argPosArr = activeFunction.args; + } + } + if (name) { res = new AscCommonExcel.CFunctionInfo(name) + //получаем массив аргументов res.argumentsValue = parseResult.getArgumentsValue(t.cellEditor._formula.Formula); if (res.argumentsValue) { var argumentsType = parseResult.activeFunction.func.argumentsType; @@ -2613,6 +2624,7 @@ argType = argumentsType[i]; } } + //вычисляем результат каждого аргумента var argCalc = ws.calculateWizardFormula(res.argumentsValue[i], argType); res.argumentsResult[i] = argCalc.str; } @@ -2650,7 +2662,7 @@ return; } - addFunction(name); + addFunction(name, true); }; WorkbookView.prototype.canEnterWizardRange = function (char) { From 594512d7e66987aed99f2f02e49451f4907ab9ea Mon Sep 17 00:00:00 2001 From: GoshaZotov Date: Thu, 14 Apr 2022 16:15:42 +0300 Subject: [PATCH 7/7] [se] By previous --- cell/model/FormulaObjects/parserFormula.js | 4 ++-- cell/view/WorkbookView.js | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cell/model/FormulaObjects/parserFormula.js b/cell/model/FormulaObjects/parserFormula.js index 1edd20e23e..c1561750a7 100644 --- a/cell/model/FormulaObjects/parserFormula.js +++ b/cell/model/FormulaObjects/parserFormula.js @@ -5247,13 +5247,13 @@ _func[cElementType.cell3D] = _func[cElementType.cell]; if (this.allFunctionsPos) { var startFuncs, endFuncs, i, j; for (i = 0; i < this.allFunctionsPos.length; i++) { - if (this.allFunctionsPos[i].start <= start && this.allFunctionsPos[i].end >= start) { + if (this.allFunctionsPos[i].start + 1 <= start && this.allFunctionsPos[i].end + 1 >= start) { if (!startFuncs) { startFuncs = []; } startFuncs.push(this.allFunctionsPos[i]); } - if (start !== end && this.allFunctionsPos[i].start <= end && this.allFunctionsPos[i].end >= end) { + if (start !== end && this.allFunctionsPos[i].start + 1 <= end && this.allFunctionsPos[i].end + 1 >= end) { if (!endFuncs) { endFuncs = []; } diff --git a/cell/view/WorkbookView.js b/cell/view/WorkbookView.js index 41805e6580..580753736c 100644 --- a/cell/view/WorkbookView.js +++ b/cell/view/WorkbookView.js @@ -2595,10 +2595,13 @@ if (cellEditMode) { //ищем общую функцию, в которой находится курсор //если начало и конец селекта в одной функции - показываем настройки для неё, если в разных - добавляем новую - var activeFunction = parseResult.getActiveFunction(t.cellEditor.selectionBegin, t.cellEditor.selectionEnd); + var _start = t.cellEditor.selectionBegin !== -1 ? t.cellEditor.selectionBegin : t.cellEditor.cursorPos; + var _end = t.cellEditor.selectionEnd !== -1 ? t.cellEditor.selectionEnd : t.cellEditor.cursorPos; + var activeFunction = parseResult.getActiveFunction(_start, _end); if (activeFunction) { parseResult.activeFunction = activeFunction; parseResult.argPosArr = activeFunction.args; + name = activeFunction.func && activeFunction.func.name; } } @@ -2642,6 +2645,9 @@ t.cellEditor.lastRangePos = parseResult.argPosArr[0].start; t.cellEditor.lastRangeLength = parseResult.argPosArr[parseResult.argPosArr.length - 1].end - parseResult.argPosArr[0].start; + + t.cellEditor.selectionBegin = t.cellEditor.selectionEnd = -1; + t.cellEditor._cleanSelection(); } } else { t.cellEditor.insertFormula(name);