Commit 9971c54a authored by Ilya Kirillov's avatar Ilya Kirillov

Смержены изменения со старого бранча для автозамены в формулах.

parent 6128c4bd
......@@ -10384,11 +10384,11 @@ ParaRun.prototype.Get_TextForAutoCorrect = function(AutoCorrectEngine, RunPos)
var Item = this.Content[nPos];
if (para_Math_Text === Item.Type || para_Math_BreakOperator === Item.Type)
{
AutoCorrectEngine.Add_Text(String.fromCharCode(Item.value), this, nPos, RunPos);
AutoCorrectEngine.Add_Text(String.fromCharCode(Item.value), this, nPos, RunPos, Item.Pos);
}
else if (para_Math_Ampersand === Item.Type)
{
AutoCorrectEngine.Add_Text('&', this, nPos, RunPos);
AutoCorrectEngine.Add_Text('&', this, nPos, RunPos, Item.Pos);
}
if (Item === ActionElement)
......
......@@ -5001,8 +5001,7 @@ CMathContent.prototype.private_IsMenuPropsForContent = function(Action)
};
CMathContent.prototype.Process_AutoCorrect = function(ActionElement)
{
if (false === this.private_NeedAutoCorrect(ActionElement))
return;
var bNeedAutoCorrect = this.private_NeedAutoCorrect(ActionElement);
var AutoCorrectEngine = new CMathAutoCorrectEngine(ActionElement);
......@@ -5029,8 +5028,32 @@ CMathContent.prototype.Process_AutoCorrect = function(ActionElement)
History.Create_NewPoint(AscDFH.historydescription_Document_MathAutoCorrect);
var bCursorStepRight = false;
var bAutoCorrectFunction = false;
var CanMakeAutoCorrectEquation = false;
var CanMakeAutoCorrectFunc = false;
var CanMakeAutoCorrect = false;
var oAutoCorrectControl = new AutoCorrectionControl(AutoCorrectEngine, this.ParaMath);
if (false === bNeedAutoCorrect && ActionElement.Type === para_Math_Text)
{
var bFindFunction = oAutoCorrectControl.FindFunction(false);
if (false === bFindFunction)
return false;
if (oAutoCorrectControl.Type === MATH_DELIMITER && oAutoCorrectControl.BrAccount.LBracket === 0x28 && oAutoCorrectControl.BrAccount.RBracket === 0x29)
oAutoCorrectControl.AutoCorrectDelimiter(AutoCorrectEngine, false);
else if (oAutoCorrectControl.Type === MATH_MATRIX)
oAutoCorrectControl.AutoCorrectMatrix(AutoCorrectEngine, false);
else if (oAutoCorrectControl.Type === MATH_EQ_ARRAY)
oAutoCorrectControl.AutoCorrectEqArray(AutoCorrectEngine, false);
else if (oAutoCorrectControl.bDelimiter && (oAutoCorrectControl.Type === MATH_RADICAL || oAutoCorrectControl.Type === MATH_PHANTOM))
oAutoCorrectControl.AutoCorrectDelimiter(AutoCorrectEngine, false);
}
else
{
// Смотрим возможно ли выполнить автозамену, если нет, тогда пробуем произвести автозамену пропуская последний символ
var CanMakeAutoCorrect = this.private_CanAutoCorrectText(AutoCorrectEngine, false);
CanMakeAutoCorrect = this.private_CanAutoCorrectText(AutoCorrectEngine, false);
if (false === CanMakeAutoCorrect)
{
......@@ -5045,25 +5068,43 @@ CMathContent.prototype.Process_AutoCorrect = function(ActionElement)
}
}
oAutoCorrectControl.SetReplaceChar(AutoCorrectEngine);
// Пробуем произвести автозамену без последнего добавленного символа
if (0x20 === ActionElement.value)
CanMakeAutoCorrectFunc = this.private_CanAutoCorrectTextFunc(AutoCorrectEngine, true);
else
CanMakeAutoCorrectFunc = this.private_CanAutoCorrectTextFunc(AutoCorrectEngine, false);
// Пробуем сделать формульную автозамену
if (false === CanMakeAutoCorrect)
if (false === CanMakeAutoCorrectFunc)
{
var CanMakeAutoCorrectEquation = false;
//if (CanMakeAutoCorrect || ( 0x28 != ActionElement.value && /*0x29 != ActionElement.value &&*/ /*0x5E!= ActionElement.value &&*/ /*0x5F!= ActionElement.value &&*/ 0x5C!= ActionElement.value /*&& 0x2B!= ActionElement.value*/))
// CanMakeAutoCorrectEquation = this.private_CanAutoCorrectEquation(AutoCorrectEngine, CanMakeAutoCorrect, bCursorStepRight);
if (CanMakeAutoCorrect || ( 0x28 != ActionElement.value && 0x5C != ActionElement.value))
CanMakeAutoCorrectEquation = oAutoCorrectControl.private_CanAutoCorrectEquation(AutoCorrectEngine, CanMakeAutoCorrect, bCursorStepRight);
}
}
if (true === CanMakeAutoCorrect || true === CanMakeAutoCorrectEquation)
if (true === bFindFunction || true === CanMakeAutoCorrect || true === CanMakeAutoCorrectEquation || CanMakeAutoCorrectFunc)
{
var ElementsCount = AutoCorrectEngine.Elements.length;
var LastElement = null;
var FirstElement = AutoCorrectEngine.Elements[ElementsCount - 1];
var FirstElement = AutoCorrectEngine.Elements[ElementsCount - 1 - AutoCorrectEngine.Shift];
var FirstElementPos = FirstElement.ElementPos;
FirstElement.Pos++;
var bReplaseShiftContent = false;
for (var nPos = 0, nCount = AutoCorrectEngine.RemoveCount; nPos < nCount; nPos++)
{
LastElement = AutoCorrectEngine.Elements[ElementsCount - nPos - 1];
/*if (CanMakeAutoCorrectEquation && AutoCorrectEngine.ActionElement.value == 0x20 && bReplaseShiftContent === false)
{
bReplaseShiftContent = true;
nPos++;
AutoCorrectEngine.RemoveCount--;
nCount--;
if (nPos >= nCount)
break;
}*/
LastElement = AutoCorrectEngine.Elements[ElementsCount - nPos - 1 - AutoCorrectEngine.Shift];
if (undefined !== LastElement.Run)
{
......@@ -5079,9 +5120,11 @@ CMathContent.prototype.Process_AutoCorrect = function(ActionElement)
}
}
if (FirstElement.Type != para_Math_Composition)
{
var NewRun = FirstElement.Run.Split2(FirstElement.Pos);
this.Internal_Content_Add(FirstElementPos + 1, NewRun, false);
}
var NewElementsCount = AutoCorrectEngine.ReplaceContent.length;
for (var nPos = 0; nPos < NewElementsCount; nPos++)
......@@ -5089,8 +5132,33 @@ CMathContent.prototype.Process_AutoCorrect = function(ActionElement)
this.Internal_Content_Add(nPos + FirstElementPos + 1, AutoCorrectEngine.ReplaceContent[nPos], false);
}
this.CurPos = FirstElementPos + NewElementsCount + 1;
this.CurPos = FirstElementPos + NewElementsCount;
if (CanMakeAutoCorrectEquation && AutoCorrectEngine.Type == MATH_NARY)
{
var oContentElem = this.Content[this.CurPos];
this.Correct_Content(true);
var CurrentContent = new CParagraphContentPos();
this.ParaMath.Get_ParaContentPos(false, false, CurrentContent);
var LeftContentPos = new CParagraphSearchPos();
this.ParaMath.Get_LeftPos(LeftContentPos, CurrentContent, 0, true);
this.ParaMath.Set_ParaContentPos(LeftContentPos.Pos, 0);
this.CurPos++;
oContentElem.CurPos = 2;
oContentElem.Content[2].Cursor_MoveToStartPos();
}
else
{
this.CurPos++;
if (AutoCorrectEngine.Shift == 0)
this.Content[this.CurPos].Cursor_MoveToStartPos();
else
this.Content[this.CurPos].Cursor_MoveToEndPos();
}
if (true === bCursorStepRight)
{
......@@ -5104,13 +5172,14 @@ CMathContent.prototype.Process_AutoCorrect = function(ActionElement)
History.Remove_LastPoint();
}
};
CMathContent.prototype.private_NeedAutoCorrect = function(ActionElement)
CMathContent.prototype.private_NeedAutoCorrect = function( ActionElement)
{
var CharCode;
if (para_Math_Ampersand == ActionElement.Type)
CharCode = 0x26;
else
CharCode = ActionElement.value;
if (1 === g_aMathAutoCorrectTriggerCharCodes[CharCode])
return true;
......@@ -5189,220 +5258,283 @@ CMathContent.prototype.private_CanAutoCorrectText = function(AutoCorrectionEngin
return Result;
};
CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionEngine, CanMakeAutoCorrect, bCursorStepRight)
{
/*CMathContent.prototype.private_AutoCorrectDelimiter = function( AutoCorrectionEngine, ActionElement)
{
var ElementsCount = AutoCorrectionEngine.Elements.length;
if (CanMakeAutoCorrect)
ElementsCount = ElementsCount - AutoCorrectionEngine.RemoveCount;
if (ElementsCount < 2)
return false;
var TempElements = [];
var TempElements2 = [];
var CurPos = ElementsCount - 1;
// Пробел в начале пропускаем
var Element = AutoCorrectionEngine.Elements[CurPos];
AutoCorrectionEngine.props = {};
var oLastElem = AutoCorrectionEngine.Elements[ElementsCount-2];
if (oLastElem.Type != para_Math_Text && oLastElem.Text != ')')
return false;
var bOpenBrk = false;
var bCloseBrk = false;
var Type = null;
var oCurElem = AutoCorrectionEngine.Elements[ElementsCount];
var bClose = false;
var bOpen = false;
var TempElements = [];
var BrAccount = new CMathBracketAcc();
if (' ' === Element.Text || ')' === Element.Text || '_' === Element.Text || 0x5E === AutoCorrectionEngine.ActionElement.value || 0x5F === AutoCorrectionEngine.ActionElement.value)
for (var i = ElementsCount-1; i >= 0; i--)
{
//проверка открытых и закрытых скобок
for (var i=ElementsCount-1; i>=0; i--)
{
oCurElem = AutoCorrectionEngine.Elements[i];
if (')' === oCurElem.Text )
var oCurElem = AutoCorrectionEngine.Elements[i];
if (oCurElem.Type === para_Math_Text && oCurElem.Text == '(')
{
BrAccount.Counter++;
bCloseBrk = true;
BrAccount.RPos = i;
if (!bClose)
return false;
BrAccount.CorrectLeft(oCurElem, i, oCurElem.Text.charCodeAt(0));
}
else if ('(' === oCurElem.Text && !bCloseBrk)
return;
else if ('(' === oCurElem.Text && bCloseBrk)
else if (oCurElem.Type === para_Math_Text && oCurElem.Text == ')')
{
BrAccount.Counter--;
bOpenBrk = true;
BrAccount.LPos = i;
if (bClose)
return false;
bClose = true;
BrAccount.CorrectRight(oCurElem, i, oCurElem.Text.charCodeAt(0));
//в первую очередь производим автозамену композиции в скобках
if ( i == BrAccount.RPos - 2)
}
else if (oCurElem.Type != para_Math_Composition)
{
var oBrElem = AutoCorrectionEngine.Elements[i+1].Element;
if (oBrElem.Type == para_Math_Composition)
continue;
}
}
this.AutoCorrectDelimiter(AutoCorrectionEngine, BrAccount, CanMakeAutoCorrect);
return true;
};*/
CMathContent.prototype.private_CanAutoCorrectTextFunc = function( AutoCorrectionEngine, bSkipLast)
{
var IndexAdd = (true === bSkipLast ? 1 : 0);
var ElementsCount = AutoCorrectionEngine.Elements.length;
if (ElementsCount < 2 + IndexAdd)
return false;
var Result = false;
var RemoveElem = null;
var RemoveCount = 0;
var ReplaceChars = [0x0020];
var AutoCorrectCount = g_aAutoCorrectMathFuncSymbols.length;
for (var nIndex = 0; nIndex < AutoCorrectCount; nIndex++)
{
var props = new CMathDelimiterPr();
props.column = 1;
var oDelimiter = new CDelimiter(props);
var AutoCorrectElement = g_aAutoCorrectMathFuncSymbols[nIndex];
var CheckString = AutoCorrectElement;
var CheckStringLen = CheckString.length;
var oDelElem = oDelimiter.getBase(0);
oDelElem.addElementToContent(oBrElem);
//AutoCorrectionEngine.ReplaceContent.push(AutoCorrectionEngine.Delimiter);
if (ElementsCount < CheckStringLen)
continue;
AutoCorrectionEngine.RemoveCount = BrAccount.RPos - BrAccount.LPos + 1 ;
AutoCorrectionEngine.ReplaceContent.unshift(oDelimiter);
return true;
var Found = true;
}
}
}
else if ('&' === oCurElem.Text || '@' === oCurElem.Text )
BrAccount.Separator = true;
else if (oCurElem.Text)
// Начинаем проверять с конца строки
for (var nStringPos = 0; nStringPos < CheckStringLen; nStringPos++)
{
switch(oCurElem.Text.charCodeAt(0))
var LastElement = AutoCorrectionEngine.Elements[ElementsCount - nStringPos - 1 - IndexAdd];
if (undefined === LastElement.Text || LastElement.Text !== CheckString.charAt(CheckStringLen - nStringPos - 1))
{
case 0x2588:
case 0x25A0: AutoCorrectionEngine.Type = MATH_MATRIX;break;
case 0x24A8: AutoCorrectionEngine.Type = MATH_MATRIX;
props = new CMathDelimiterPr();
props.column = 1;
AutoCorrectionEngine.Delimiter = new CDelimiter(props);
break;
case 0x24A9: AutoCorrectionEngine.Type = MATH_MATRIX;
props = new CMathDelimiterPr();
props.column = 1;
props.begChr = 0x2016;
props.endChr = 0x2016;
AutoCorrectionEngine.Delimiter = new CDelimiter(props);
break;
case 0x25AD: AutoCorrectionEngine.Type = MATH_BORDER_BOX;break;
case 0x25A1: AutoCorrectionEngine.Type = MATH_BOX;break;
case 0x00AF:
case 0x033F: AutoCorrectionEngine.Type = MATH_BAR;
AutoCorrectionEngine.props = {pos: LOCATION_TOP};
break;
case 0x2581: AutoCorrectionEngine.Type = MATH_BAR;
break;
case 0x221A: AutoCorrectionEngine.Type = MATH_RADICAL;break;
case 0x221B: TempElements2.splice(0, 0, {Text:'3'});
AutoCorrectionEngine.Type = MATH_RADICAL;
break;
case 0x221C: TempElements2.splice(0, 0, {Text:'4'});
AutoCorrectionEngine.Type = MATH_RADICAL;
break;
case 0x2211: AutoCorrectionEngine.Type = MATH_NARY;break;
case 0x23E0:
case 0x23DC: AutoCorrectionEngine.Type = MATH_GROUP_CHARACTER;
AutoCorrectionEngine.props = {chr: oCurElem.Text.charCodeAt(0), pos: LOCATION_TOP, vertJc: VJUST_BOT};
break;
case 0x23DD: AutoCorrectionEngine.Type = MATH_GROUP_CHARACTER;
AutoCorrectionEngine.props = {chr: oCurElem.Text.charCodeAt(0)};
break;
case 0x23DF: AutoCorrectionEngine.Type = MATH_GROUP_CHARACTER;
break;
case 0x23DE: AutoCorrectionEngine.Type = MATH_GROUP_CHARACTER;
AutoCorrectionEngine.props = {chr: 0x23DE, pos: LOCATION_TOP, vertJc: VJUST_BOT};
break;
case 0x27E1: AutoCorrectionEngine.Type = MATH_PHANTOM;
AutoCorrectionEngine.props = {show: 0};
break;
case 0x2B04: AutoCorrectionEngine.Type = MATH_PHANTOM;
AutoCorrectionEngine.props = {show: 0, zeroAsc: 1, zeroDesc: 1};
break;
case 0x21F3: AutoCorrectionEngine.Type = MATH_PHANTOM;
AutoCorrectionEngine.props = {show: 0, zeroWid: 1};
Found = false;
break;
case 0x24B8: break;
}
if (AutoCorrectionEngine.Type)
break;
}
if ( Found === true )
{
var nFirstElem = ElementsCount - CheckStringLen - 1 - IndexAdd;
if (nFirstElem < 0 || (CheckStringLen >= 0 && (AutoCorrectionEngine.Elements[nFirstElem].Type === para_Math_Composition || AutoCorrectionEngine.Elements[nFirstElem].Text.charCodeAt(0) == 0x0020)))
RemoveElem = AutoCorrectElement;
else
break;
}
//если это пробел не в скобках оставляем его
if (' ' === Element.Text && (!bOpenBrk || (bOpenBrk && bCloseBrk)))
CurPos--;
}
if ( AutoCorrectionEngine.Type == MATH_RADICAL && bOpenBrk && bCloseBrk && BrAccount.Counter == 0 && BrAccount.Separator)
{
var arrContent = [];
var col = 0;
arrContent[col] = [];
for (var i=BrAccount.LPos+1; i<BrAccount.RPos; i++)
if (RemoveElem)
{
oCurElem = AutoCorrectionEngine.Elements[i];
if ( '&' === oCurElem.Text )
var Pr = {ctrPrp: new CTextPr()};
var MathFunc = new CMathFunc(Pr);
var MathContent = MathFunc.getFName();
var MathRun = new ParaRun(this.Paragraph, true);
for (var nCharPos = 0, nTextLen = RemoveElem.length; nCharPos < nTextLen; nCharPos++)
{
col++;
arrContent[col] = [];
}
var oText = null;
if (0x0026 == RemoveElem.charCodeAt(nCharPos))
oText = new CMathAmp();
else
{
if (oCurElem.Text)
{
var MathText = new CMathText();
MathText.add(oCurElem.Text.charCodeAt(0));
arrContent[col].push( MathText );
oText = new CMathText(false);
oText.addTxt(RemoveElem[nCharPos]);
}
else
arrContent[col].push( oCurElem.Element );
MathRun.Add(oText, true);
}
MathRun.Math_Apply_Style(STY_PLAIN);
MathContent.Internal_Content_Add(0, MathRun);
AutoCorrectionEngine.RemoveCount = CheckStringLen + IndexAdd;
AutoCorrectionEngine.ReplaceContent.push(MathFunc);
Result = true;
}
var props = new CMathRadicalPr();
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
var Radical = new CRadical(props);
return Result;
};
var Base = Radical.getBase();
var Degree = Radical.getDegree();
function AutoCorrectionControl (AutoCorrectionEngine, ParaMath)
{
this.TempElements = [];
this.TempElements2 = [];
this.TempElements3 = [];
this.props = {};
this.BrAccount = new CMathBracketAcc();
for (var i=0; i<arrContent[1].length; i++)
this.ParaMath = ParaMath;
this.ActionElement = AutoCorrectionEngine.ActionElement;
this.ActionElementCode = AutoCorrectionEngine.ActionElement.value;
this.ReplaceCode = null;
this.Delimiter = null;
this.bDelimiter = false;
this.bOpenBrk = false;
this.bCloseBrk = false;
this.RemoveCount = AutoCorrectionEngine.RemoveCount;
this.Elements = AutoCorrectionEngine.Elements;
this.ElementsCount = AutoCorrectionEngine.Elements.length;
}
AutoCorrectionControl.prototype.SetReplaceChar = function(AutoCorrectionEngine)
{
this.Elements = AutoCorrectionEngine.Elements;
if (AutoCorrectionEngine.ReplaceContent.length > 0)
this.ReplaceCode = AutoCorrectionEngine.ReplaceContent[0].Content[0].value;
this.RemoveCount = AutoCorrectionEngine.RemoveCount;
this.ElementsCount = AutoCorrectionEngine.Elements.length;
};
AutoCorrectionControl.prototype.PackTextToContent = function(Element, TempElements, AutoCorrectionEngine, bReplaceBrackets)
{
var len = TempElements.length;
if (len > 1 && TempElements[0].Type != para_Math_Composition && bReplaceBrackets)
if ( (TempElements[0].Text === '(' && TempElements[len-1].Text === ')') || (TempElements[0].Text.charCodeAt(0) === 0x3016 && TempElements[len-1].Text.charCodeAt(0) === 0x3017))
{
var CurElem = arrContent[1][i];
if (para_Math_Text == CurElem.Type)
TempElements.splice(len-1,1);
TempElements.splice(0,1);
len -= 2 ;
}
for (var nPos = 0; nPos < len; nPos++)
{
if (undefined === TempElements[nPos].Text)
Element.Internal_Content_Add(nPos, TempElements[nPos].Element);
else
{
var MathRun = new ParaRun(this.ParaMath.Paragraph, true);
MathRun.Set_Pr(AutoCorrectionEngine.TextPr.Copy());
MathRun.Set_MathPr(AutoCorrectionEngine.MathPr.Copy());
MathRun.Add_ToContent(0, CurElem);
Base.Internal_Content_Add(Base.length, MathRun);
var MathText = new CMathText();
MathText.add(TempElements[nPos].Text.charCodeAt(0));
MathRun.Add_ToContent(nPos, MathText);
Element.Internal_Content_Add(nPos, MathRun);
}
else
Base.Internal_Content_Add(Base.length, CurElem);
}
for (var i=0; i<arrContent[0].length; i++)
{
var CurElem = arrContent[0][i];
if (para_Math_Text == CurElem.Type)
};
AutoCorrectionControl.prototype.AutoCorrectAccent = function(AutoCorrectionEngine, CanMakeAutoCorrect)
{
var props = new CMathAccentPr();
props.chr = this.Elements[this.BrAccount.nRRPos+1].Text;
var oAccent = new CAccent(props);
var oBase = oAccent.getBase(0);
var TempElements = [];
var nRemoveCount = 2;
if (this.bOpenBrk && this.bCloseBrk)
{
var MathRun = new ParaRun(this.ParaMath.Paragraph, true);
MathRun.Set_Pr(AutoCorrectionEngine.TextPr.Copy());
MathRun.Set_MathPr(AutoCorrectionEngine.MathPr.Copy());
MathRun.Add_ToContent(0, CurElem);
Degree.Internal_Content_Add(Degree.length, MathRun);
for( var i = this.BrAccount.nRPos-1; i>this.BrAccount.nLPos; i--)
TempElements.splice(0, 0, this.Elements[i]);
nRemoveCount = this.BrAccount.nRPos - this.BrAccount.nLPos + 2;
}
else
Degree.Internal_Content_Add(Degree.length, CurElem);
}
TempElements.splice(0, 0, AutoCorrectionEngine.Elements[this.CurPos-1]);
this.PackTextToContent(oBase, TempElements, AutoCorrectionEngine);
AutoCorrectionEngine.RemoveCount = BrAccount.RPos - BrAccount.LPos + 2 + 1;
AutoCorrectionEngine.ReplaceContent.unshift(Radical);
if (CanMakeAutoCorrect)
nRemoveCount += AutoCorrectionEngine.RemoveCount;
else if (0x20 == this.ActionElementCode)
nRemoveCount++;
AutoCorrectionEngine.RemoveCount = nRemoveCount;
AutoCorrectionEngine.ReplaceContent.unshift(oAccent);
return true;
}
};
AutoCorrectionControl.prototype.AutoCorrectDelimiter = function(AutoCorrectionEngine, CanMakeAutoCorrect)
{
var props = new CMathDelimiterPr();
props.column = 1;
props.begChr = this.BrAccount.LBracket;
props.endChr = this.BrAccount.RBracket;
var oDelimiter = new CDelimiter(props);
if ( AutoCorrectionEngine.Type == MATH_MATRIX && bOpenBrk && bCloseBrk && BrAccount.Counter == 0)
{
var oBase = oDelimiter.getBase(0);
var TempElements = [];
for( var i = this.BrAccount.nRPos-1; i>this.BrAccount.nLPos; i--)
TempElements.splice(0, 0, AutoCorrectionEngine.Elements[i]);
this.PackTextToContent(oBase, TempElements, AutoCorrectionEngine);
AutoCorrectionEngine.Shift = AutoCorrectionEngine.Elements.length - 1 - this.BrAccount.nRPos;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.Shift--;
var nRemoveCount = this.BrAccount.nRPos - this.BrAccount.nLPos + 1;
if (CanMakeAutoCorrect)
nRemoveCount += AutoCorrectionEngine.RemoveCount;
else if (0x20 == this.ActionElementCode)
nRemoveCount++;
AutoCorrectionEngine.RemoveCount = nRemoveCount;
AutoCorrectionEngine.ReplaceContent.unshift(oDelimiter);
};
AutoCorrectionControl.prototype.AutoCorrectPhantom = function(AutoCorrectionEngine, CanMakeAutoCorrect)
{
var props = new CMathPhantomPr();
props.Set_FromObject(this.props);
var oPhantom = new CPhantom(props);
var oBase = oPhantom.getBase();
var TempElements = [];
for( var i = this.BrAccount.nRPos-1; i>this.BrAccount.nLPos; i--)
TempElements.splice(0, 0, AutoCorrectionEngine.Elements[i]);
AutoCorrectionEngine.Shift = AutoCorrectionEngine.Elements.length - 1 - this.BrAccount.nRPos;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.Shift--;
this.PackTextToContent(oBase, TempElements, AutoCorrectionEngine);
var nRemoveCount = this.BrAccount.nRPos - this.BrAccount.nLPos + 2;
if (CanMakeAutoCorrect)
nRemoveCount += AutoCorrectionEngine.RemoveCount;
else if (0x20 == this.ActionElementCode)
nRemoveCount++;
AutoCorrectionEngine.RemoveCount = nRemoveCount;
AutoCorrectionEngine.ReplaceContent.unshift(oPhantom);
};
AutoCorrectionControl.prototype.AutoCorrectMatrix = function(AutoCorrectionEngine, CanMakeAutoCorrect)
{
var arrContent = [];
var col = 0;
var row = 0;
var mcs = [];
var oCurElem = null;
arrContent[row] = [];
arrContent[row][col] = [];
mcs[0] = {count: 1, mcJc: 0};
for (var i=BrAccount.LPos+1; i<BrAccount.RPos; i++)
for (var i=this.BrAccount.nLPos+1; i<this.BrAccount.nRPos; i++)
{
oCurElem = AutoCorrectionEngine.Elements[i];
if ( '&' === oCurElem.Text || '@' === oCurElem.Text)
......@@ -5424,7 +5556,7 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
}
else
{
if (oCurElem.Text)
if (para_Math_Text == oCurElem.Type || para_Math_BreakOperator == oCurElem.Type)
{
var MathText = new CMathText();
MathText.add(oCurElem.Text.charCodeAt(0));
......@@ -5449,7 +5581,7 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
for (var l=0; l<Content.length; l++)
{
var CurElem = Content[l];
if (para_Math_Text == CurElem.Type)
if (para_Math_Text == CurElem.Type || para_Math_BreakOperator === CurElem.Type)
{
var MathRun = new ParaRun(this.ParaMath.Paragraph, true);
MathRun.Set_Pr(AutoCorrectionEngine.TextPr.Copy());
......@@ -5463,94 +5595,731 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
}
}
AutoCorrectionEngine.RemoveCount = BrAccount.RPos - BrAccount.LPos + 2 + 1;
AutoCorrectionEngine.Shift = AutoCorrectionEngine.Elements.length - 1 - this.BrAccount.nRPos;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.Shift--;
var nRemoveCount = this.BrAccount.nRPos - this.BrAccount.nLPos + 2;
if (CanMakeAutoCorrect)
nRemoveCount += AutoCorrectionEngine.RemoveCount;
else if (0x20 == this.ActionElementCode)
nRemoveCount++;
AutoCorrectionEngine.RemoveCount = nRemoveCount;
if (AutoCorrectionEngine.Delimiter)
if (this.Delimiter)
{
var oDelElem = AutoCorrectionEngine.Delimiter.getBase(0);
var oDelElem = this.Delimiter.getBase(0);
oDelElem.addElementToContent(Matrix);
AutoCorrectionEngine.ReplaceContent.push(AutoCorrectionEngine.Delimiter);
AutoCorrectionEngine.ReplaceContent.unshift(this.Delimiter);
}
else
AutoCorrectionEngine.ReplaceContent.push(Matrix);
AutoCorrectionEngine.ReplaceContent.unshift(Matrix);
};
AutoCorrectionControl.prototype.AutoCorrectEqArray = function(AutoCorrectionEngine, CanMakeAutoCorrect)
{
var arrContent = [];
var col = 0;
var row = 0;
var mcs = [];
var oCurElem = null;
arrContent[row] = [];
return true;
}
for (var i=this.BrAccount.nLPos+1; i<this.BrAccount.nRPos; i++)
{
oCurElem = AutoCorrectionEngine.Elements[i];
if ('@' === oCurElem.Text)
{
row++;
arrContent[row] = [];
}
else
{
if (para_Math_Text == oCurElem.Type || para_Math_BreakOperator == oCurElem.Type)
{
var MathText = new CMathText();
MathText.add(oCurElem.Text.charCodeAt(0));
arrContent[row].push( MathText );
}
else if (para_Math_Ampersand == oCurElem.Type)
{
var MathText = new CMathAmp();
arrContent[row].push( MathText );
}
else
arrContent[row].push( oCurElem.Element );
}
}
bOpenBrk = false;
bCloseBrk = false;
var props = new CMathEqArrPr();
props.row = row+1;
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
var EqArray = new CEqArray(props);
for (var i=0; i<arrContent.length; i++)
{
var Elem = EqArray.getElement(i);
var Content = arrContent[i];
for (var l=0; l<Content.length; l++)
{
var CurElem = Content[l];
if (para_Math_Composition != CurElem.Type)
{
var MathRun = new ParaRun(this.ParaMath.Paragraph, true);
MathRun.Set_Pr(AutoCorrectionEngine.TextPr.Copy());
MathRun.Set_MathPr(AutoCorrectionEngine.MathPr.Copy());
MathRun.Add_ToContent(0, CurElem);
Elem.Internal_Content_Add(Elem.length, MathRun);
}
else
Elem.Internal_Content_Add(Elem.length, CurElem);
}
}
AutoCorrectionEngine.Shift = AutoCorrectionEngine.Elements.length - 1 - this.BrAccount.nRPos;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.Shift--;
var nRemoveCount = this.BrAccount.nRPos - this.BrAccount.nLPos + 2;
if (CanMakeAutoCorrect)
nRemoveCount += AutoCorrectionEngine.RemoveCount;
else if (0x20 == this.ActionElementCode)
nRemoveCount++;
AutoCorrectionEngine.RemoveCount = nRemoveCount;
if (this.Delimiter)
{
var oDelElem = this.Delimiter.getBase(0);
oDelElem.addElementToContent(EqArray);
AutoCorrectionEngine.ReplaceContent.unshift(this.Delimiter);
}
else
AutoCorrectionEngine.ReplaceContent.unshift(EqArray);
};
AutoCorrectionControl.prototype.AutoCorrectRadical = function(AutoCorrectionEngine, CanMakeAutoCorrect)
{
var oCurElem = null;
var arrContent = [];
var col = 0;
arrContent[col] = [];
for (var i = this.BrAccount.nLPos + 1; i < this.BrAccount.nRPos; i++)
{
oCurElem = AutoCorrectionEngine.Elements[i];
if ( '&' === oCurElem.Text )
{
col++;
arrContent[col] = [];
}
else
{
if (oCurElem.Text)
{
var MathText = new CMathText();
MathText.add(oCurElem.Text.charCodeAt(0));
arrContent[col].push( MathText );
}
else
arrContent[col].push( oCurElem.Element );
}
}
var props = new CMathRadicalPr();
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
var Radical = new CRadical(props);
var Base = Radical.getBase();
var Degree = Radical.getDegree();
for (var i=0; i<arrContent[1].length; i++)
{
var CurElem = arrContent[1][i];
if (para_Math_Text == CurElem.Type || para_Math_BreakOperator === CurElem.Type)
{
var MathRun = new ParaRun(this.ParaMath.Paragraph, true);
MathRun.Set_Pr(AutoCorrectionEngine.TextPr.Copy());
MathRun.Set_MathPr(AutoCorrectionEngine.MathPr.Copy());
MathRun.Add_ToContent(0, CurElem);
Base.Internal_Content_Add(Base.length, MathRun);
}
else
Base.Internal_Content_Add(Base.length, CurElem);
}
for (var i=0; i<arrContent[0].length; i++)
{
var CurElem = arrContent[0][i];
if (para_Math_Text == CurElem.Type || para_Math_BreakOperator === CurElem.Type)
{
var MathRun = new ParaRun(this.ParaMath.Paragraph, true);
MathRun.Set_Pr(AutoCorrectionEngine.TextPr.Copy());
MathRun.Set_MathPr(AutoCorrectionEngine.MathPr.Copy());
MathRun.Add_ToContent(0, CurElem);
Degree.Internal_Content_Add(Degree.length, MathRun);
}
else
Degree.Internal_Content_Add(Degree.length, CurElem);
}
AutoCorrectionEngine.RemoveCount = this.BrAccount.nRPos - this.BrAccount.nLPos + 2 + 1;
AutoCorrectionEngine.ReplaceContent.unshift(Radical);
};
AutoCorrectionControl.prototype.FindFunction = function(CanMakeAutoCorrect)
{
var oRigthCommandType = null;
var oLeftCommandType = null;
var bOf = false;
var bAddAccent = false;
var nCountElems = this.ElementsCount;
if (CanMakeAutoCorrect)
nCountElems = this.ElementsCount - this.RemoveCount;
if (nCountElems < 2)
return false;
var nCurPos = nCountElems - 1;
var oCurElem = this.Elements[nCurPos];
if (oCurElem.Type === para_Math_Text && oCurElem.Text == ' ')
{
nCurPos--;
nCountElems--;
this.ElementsCount--;
oCurElem = this.Elements[nCurPos];
}
// 2 пробела подряд в конце
if (oCurElem.Type === para_Math_Text && oCurElem.Text == ' ')
return false;
//автозамена производится только до оператора остановки ( + - * и тд )
else if (CanMakeAutoCorrect && oCurElem.Type === para_Math_BreakOperator)
return false;
else if (CanMakeAutoCorrect && this.ReplaceCode == 0x8289)
oRigthCommandType = MATH_RUN;
//проверка открытых и закрытых скобок
for (var i = nCurPos; i >= 0; i--)
{
oCurElem = this.Elements[i];
if (para_Math_Composition == oCurElem.Type)
continue;
else if (oCurElem.Type === para_Math_Text && oCurElem.Text === '(' && this.bCloseBrk)
{
if (this.BrAccount.LBracket == 0x7C)
{
this.BrAccount.CorrectLeftSeparate(oCurElem, i, oCurElem.Text.charCodeAt(0));
this.bOpenBrk = true;
oLeftCommandType = MATH_DELIMITER;
this.bDelimiter = true;
}
else
{
this.BrAccount.CorrectLeft(oCurElem, i, oCurElem.Text.charCodeAt(0));
this.bOpenBrk = true;
if (this.BrAccount.nCounter < 0)
break;
//для дроби и степени контент в скобках не заменяем на delimiter
if (0x5E != this.ActionElementCode && 0x5F != this.ActionElementCode && 0x2F != this.ActionElementCode)
{
oLeftCommandType = MATH_DELIMITER;
this.bDelimiter = true;
}
}
}
else if (oCurElem.Text === ')')
{
this.BrAccount.CorrectRight(oCurElem, i, oCurElem.Text.charCodeAt(0));
this.bCloseBrk = true;
}
else if (g_MathLeftBracketAutoCorrectCharCodes[oCurElem.Text.charCodeAt(0)] && this.bCloseBrk)
{
if (this.BrAccount.LBracket == 0x7C)
{
this.BrAccount.CorrectLeftSeparate(oCurElem, i, oCurElem.Text.charCodeAt(0));
this.bOpenBrk = true;
oLeftCommandType = MATH_DELIMITER;
this.bDelimiter = true;
}
else
{
this.BrAccount.CorrectLeft(oCurElem, i, oCurElem.Text.charCodeAt(0));
this.bOpenBrk = true;
if (this.BrAccount.nCounter < 0)
break;
//для дроби и степени контент в скобках не заменяем на delimiter
if (0x5E != this.ActionElementCode && 0x5F != this.ActionElementCode && 0x2F != this.ActionElementCode)
{
oLeftCommandType = MATH_DELIMITER;
this.bDelimiter = true;
}
}
}
else if (g_MathRightBracketAutoCorrectCharCodes[oCurElem.Text.charCodeAt(0)])
{
this.BrAccount.CorrectRight(oCurElem, i, oCurElem.Text.charCodeAt(0));
this.bCloseBrk = true;
}
else if (oCurElem.Text === '|')
{
var code = oCurElem.Text.charCodeAt(0);
this.BrAccount.Elems.unshift(i, code);
if (this.bCloseBrk == false)
{
this.BrAccount.CorrectRight(oCurElem, i, oCurElem.Text.charCodeAt(0));
this.bCloseBrk = true;
}
else if (this.bCloseBrk == true && this.bOpenBrk == false)
{
this.BrAccount.CorrectLeft(oCurElem, i, oCurElem.Text.charCodeAt(0));
this.bOpenBrk = true;
if (this.BrAccount.nCounter < 0)
break;
oLeftCommandType = MATH_DELIMITER;
this.bDelimiter = true;
}
else if (this.bCloseBrk == true && this.bOpenBrk == true)
{
if (this.BrAccount.LBracket == 0x7C)
{
this.BrAccount.CorrectLeftSeparate(oCurElem, i, oCurElem.Text.charCodeAt(0));
this.bOpenBrk = true;
oLeftCommandType = MATH_DELIMITER;
this.bDelimiter = true;
}
else
{
this.BrAccount.CorrectLeft(oCurElem, i, oCurElem.Text.charCodeAt(0));
this.bOpenBrk = true;
if (this.BrAccount.nCounter < 0)
break;
oLeftCommandType = MATH_DELIMITER;
this.bDelimiter = true;
}
}
}
else if (oCurElem.Text === '(' && !this.bCloseBrk)
{
if (g_MathRightBracketAutoCorrectCharCodes[this.ActionElementCode] || g_aMathAutoCorrectFracCharCodes[this.ActionElementCode])
break;
else
return;
}
else if (oCurElem.Type === para_Math_BreakOperator && oCurElem.Text.charCodeAt(0) == 0x5C)
{
if (i < nCurPos)
{
var oPrevElem = this.Elements[i + 1];
if (oPrevElem.Type === para_Math_Text && oPrevElem.Text === '/')
break;
}
return false;
}
else if (oCurElem.Type === para_Math_Text && oCurElem.Text.charCodeAt(0) == 0x2592) // \of
{
bOf = true;
break;
}
else if (oCurElem.Type === para_Math_Text && oCurElem.Text == ' ' && this.BrAccount.nCounter < 0)
break;
else if (oCurElem.Type === para_Math_Text && oCurElem.Text == ' ' && !this.bCloseBrk)
break;
else if (oCurElem.Type === para_Math_Text && oCurElem.Text == ' ' && this.bCloseBrk && this.BrAccount.nCounter == 0)
break;
else if ('&' === oCurElem.Text || '@' === oCurElem.Text)
this.BrAccount.bSeparator = true;
else if (q_aMathAutoCorrectAccentCharCodes[oCurElem.Text.charCodeAt(0)])
{
oRigthCommandType = MATH_ACCENT;
}
else if (oCurElem.Type === para_Math_Text)
{
var oChar = oCurElem.Text.charCodeAt(0);
if (q_aMathAutoCorrectControlAggregationCodes[oChar])
oLeftCommandType = MATH_NARY;
else
{
switch (oChar)
{
case 0x24B8:
oLeftCommandType = MATH_EQ_ARRAY;
this.props = new CMathDelimiterPr();
this.props.begChr = 0x007B;
this.props.endChr = -1;
this.props.column = 1;
this.Delimiter = new CDelimiter(this.props);
break;
case 0x2588:
oLeftCommandType = MATH_EQ_ARRAY;
break;
case 0x25A0:
oLeftCommandType = MATH_MATRIX;
break;
case 0x24A8:
oLeftCommandType = MATH_MATRIX;
this.props = new CMathDelimiterPr();
this.props.column = 1;
this.Delimiter = new CDelimiter(this.props);
break;
case 0x24A9:
oLeftCommandType = MATH_MATRIX;
this.props = new CMathDelimiterPr();
this.props.column = 1;
this.props.begChr = 0x2016;
this.props.endChr = 0x2016;
this.Delimiter = new CDelimiter(this.props);
break;
case 0x25AD:
oLeftCommandType = MATH_BORDER_BOX;
break;
case 0x25A1:
oLeftCommandType = MATH_BOX;
break;
case 0x00AF:
case 0x033F:
oLeftCommandType = MATH_BAR;
this.props = {pos : LOCATION_TOP};
break;
case 0x2581:
oLeftCommandType = MATH_BAR;
break;
case 0x221A:
oLeftCommandType = MATH_RADICAL;
break;
case 0x221B:
TempElements2.splice(0, 0, {Text : '3'});
oLeftCommandType = MATH_RADICAL;
break;
case 0x221C:
TempElements2.splice(0, 0, {Text : '4'});
oLeftCommandType = MATH_RADICAL;
break;
case 0x23E0:
case 0x23DC:
oLeftCommandType = MATH_GROUP_CHARACTER;
this.props = {chr : oCurElem.Text.charCodeAt(0), pos : LOCATION_TOP, vertJc : VJUST_BOT};
break;
case 0x23DD:
oLeftCommandType = MATH_GROUP_CHARACTER;
this.props = {chr : oCurElem.Text.charCodeAt(0)};
break;
case 0x23DF:
oLeftCommandType = MATH_GROUP_CHARACTER;
break;
case 0x23DE:
oLeftCommandType = MATH_GROUP_CHARACTER;
this.props = {chr : 0x23DE, pos : LOCATION_TOP, vertJc : VJUST_BOT};
break;
case 0x24AD:
if (bOf)
oLeftCommandType = MATH_RADICAL;
else
return false;
break;
}
}
if (oLeftCommandType == MATH_DELIMITER && this.BrAccount.LBracket == 0x7C)
{
for (var j = i - 1; j >= 0; j--)
{
oCurElem = this.Elements[j];
if (oCurElem.Type === para_Math_Text && oCurElem.Text == ' ' && this.BrAccount.nCounter < 0)
break;
else if (oCurElem.Type === para_Math_Text && oCurElem.Text == ' ' && !this.bCloseBrk)
break;
else if (oCurElem.Type === para_Math_Text && oCurElem.Text == ' ' && this.bCloseBrk && this.BrAccount.nCounter == 0)
break;
else if (oCurElem.Text == '(' && this.BrAccount.nCounter == 0)
this.BrAccount.CorrectLeftSeparate(oCurElem, j, oCurElem.Text.charCodeAt(0));
}
break;
}
else if (oLeftCommandType != null)
break;
}
else if (oCurElem.Type === para_Math_BreakOperator)
{
var oChar = oCurElem.Text.charCodeAt(0);
switch (oChar)
{
case 0x27E1:
oLeftCommandType = MATH_PHANTOM;
this.props = {show : 0};
break;
case 0x2B04:
oLeftCommandType = MATH_PHANTOM;
this.props = {show : 0, zeroAsc : 1, zeroDesc : 1};
break;
case 0x21F3:
oLeftCommandType = MATH_PHANTOM;
this.props = {show : 0, zeroWid : 1};
break;
}
if (oLeftCommandType || !this.bCloseBrk)
break;
}
}
if (oRigthCommandType)
{
this.Type = oRigthCommandType;
}
//сюда попадаем, если будет двойная автозамена символ+формула
else if (CanMakeAutoCorrect)
{
if (oLeftCommandType)
{
//если это delimiter то ничего не делаем
if (oLeftCommandType == MATH_DELIMITER)
return false;
// для n-арных операторов делается только 1 автозамена
else if (CanMakeAutoCorrect && (oLeftCommandType == MATH_NARY || oLeftCommandType == MATH_RADICAL))
return false;
else
{
bAddAccent = true;
this.Type = oLeftCommandType;
}
}
//если пришел accent на одну букву то выходим, тк сделается просто автозамена символа
else if (!this.bOpenBrk && !this.bCloseBrk && q_aMathAutoCorrectAccentCharCodes[this.ReplaceCode])
return false;
}
else
this.Type = oLeftCommandType;
this.CurPos = nCurPos;
return true;
};
AutoCorrectionControl.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionEngine, CanMakeAutoCorrect, bCursorStepRight)
{
var TempElements = [];
var TempElementsPos = [];
var TempElements2 = [];
var TempElements3 = [];
var bOf = false;
this.FindFunction(CanMakeAutoCorrect);
if ( this.Type == MATH_ACCENT)
{
this.AutoCorrectAccent(AutoCorrectionEngine, CanMakeAutoCorrect );
return true;
}
if ( this.Type == MATH_RADICAL && this.bOpenBrk && this.bCloseBrk && this.BrAccount.nCounter == 0 && this.BrAccount.bSeparator)
{
this.AutoCorrectRadical(AutoCorrectionEngine, CanMakeAutoCorrect);
return true;
}
if ( this.Type == MATH_MATRIX && this.bOpenBrk && this.bCloseBrk && this.BrAccount.nCounter == 0)
{
this.AutoCorrectMatrix(AutoCorrectionEngine, CanMakeAutoCorrect);
return true;
}
if ( this.Type == MATH_EQ_ARRAY && this.bOpenBrk && this.bCloseBrk && this.BrAccount.nCounter == 0)
{
this.AutoCorrectEqArray(AutoCorrectionEngine, CanMakeAutoCorrect);
return true;
}
if ( this.Type == MATH_PHANTOM && this.bOpenBrk && this.bCloseBrk && this.BrAccount.nCounter == 0)
{
this.AutoCorrectPhantom(AutoCorrectionEngine, CanMakeAutoCorrect);
return true;
}
if ( this.Type == MATH_DELIMITER && this.bOpenBrk && this.bCloseBrk && (this.BrAccount.LBracketlvl2 != null || this.BrAccount.RBracketlvl2 != null))
{
if ( (this.BrAccount.LBracket == 0x7C && this.BrAccount.RBracket != 0x7C) || (this.BrAccount.LBracket != 0x7C && this.BrAccount.RBracket == 0x7C))
return false;
else if ( this.BrAccount.LBracket == 0x7C && this.BrAccount.RBracket == 0x7C && this.BrAccount.LBracketlvl1 != null)
return false;
//this.BrAccount.Counted();
this.AutoCorrectDelimiter(AutoCorrectionEngine, CanMakeAutoCorrect);
return true;
}
var bOpenBrk = false;
var bCloseBrk = false;
var CurPos = this.CurPos;
while (CurPos >= 0)
{
var Element = AutoCorrectionEngine.Elements[CurPos];
var Element = this.Elements[CurPos];
if (undefined === Element.Text)
{
TempElements.splice(0, 0, Element);
else if ('(' === Element.Text)
TempElementsPos.splice(0, 0, CurPos);
}
else if ( '|' === Element.Text)
{
if (bCloseBrk && !bOpenBrk)
{
this.Type = MATH_DELIMITER;
CurPos--;
break;
}
else
TempElements2.splice(0, 0, Element);
}
else if (Element.Text === ')') // )
{
TempElements.splice(0, 0, Element);
TempElementsPos.splice(0, 0, CurPos);
bCloseBrk = true;
}
else if ( Element.Text === '(' ) // (
{
if (!bCloseBrk)
return false;
if (bOpenBrk)
{
//CurPos--; // a^((a/2))
break;
}
TempElements.splice(0, 0, Element);
TempElementsPos.splice(0, 0, CurPos);
bOpenBrk = true;
}
else if (')' === Element.Text)
if (this.ActionElementCode === 0x20)
{
TempElements.splice(0, 0, Element);
bCloseBrk = true;
if (CurPos-1 > 0) // ((a/1(a+1)
{
var Elem = this.Elements[CurPos-1];
if ( para_Math_Text == Elem.Type && '/' != Elem.Text && '_' != Elem.Text && '^' != Elem.Text && 0x00A6 != Elem.Text.charCodeAt(0) && 0x2592 != Elem.Text.charCodeAt(0)
&& !q_aMathAutoCorrectControlCharCodes[Elem.Text.charCodeAt(0)] )
break;
}
}
}
else if ('/' === Element.Text)
{
AutoCorrectionEngine.Type = MATH_FRACTION;
//введены символы _ ^ + -
if (this.ActionElement.Type == para_Math_Text && (this.ActionElementCode == 0x005E || this.ActionElementCode == 0x005F)) // a/a_
return false;
this.Type = MATH_FRACTION;
if (CurPos-1 > 0)
{
Element = AutoCorrectionEngine.Elements[CurPos-1];
if ( 0x005C === Element.Text.charCodeAt(0))
Element = this.Elements[CurPos-1];
if ( (para_Math_Text == Element.Type || para_Math_BreakOperator == Element.Type) && 0x005C === Element.Text.charCodeAt(0))
{
this.props = {type: LINEAR_FRACTION};
CurPos--;
}
}
CurPos--;
break;
}
else if ( 0x221A === Element.Text.charCodeAt(0))
{
this.Type = MATH_RADICAL;
break;
}
else if ( 0x25AD === Element.Text.charCodeAt(0))
{
this.Type = MATH_BORDER_BOX;
break;
}
else if ( 0x25A1 === Element.Text.charCodeAt(0))
{
AutoCorrectionEngine.props = {type: LINEAR_FRACTION};
this.Type = MATH_BOX;
break;
}
else if ( 0x2044 === Element.Text.charCodeAt(0))
{
this.Type = MATH_FRACTION;
this.props = {type: SKEWED_FRACTION};
CurPos--;
break;
}
else if ('^' === Element.Text)
{
//если скобки одинаковые - то степень, разные - delimiter
if( this.Type == MATH_NARY || !this.Type || ( this && (( this.BrAccount.LBracket == 0x28 && this.BrAccount.RBracket == 0x29) || ( this.BrAccount.LBracket == 0x3016 && this.BrAccount.RBracket == 0x3017))))
{
TempElements.Type = DEGREE_SUPERSCRIPT;
this.Kind = DEGREE_SUPERSCRIPT;
this.Type = MATH_DEGREE;
}
CurPos--;
break;
}
else if ('_' === Element.Text)
{
//если скобки одинаковые - то степень, разные - delimiter
if( this.Type == MATH_NARY || !this.Type || ( this && (( this.BrAccount.LBracket == 0x28 && this.BrAccount.RBracket == 0x29) || ( this.BrAccount.LBracket == 0x3016 && this.BrAccount.RBracket == 0x3017))))
{
TempElements.Type = DEGREE_SUBSCRIPT;
this.Kind = DEGREE_SUBSCRIPT;
this.Type = MATH_DEGREE;
}
CurPos--;
break;
}
else if ( 0x2044 === Element.Text.charCodeAt(0))
else if ( 0x00A6 === Element.Text.charCodeAt(0) )
{
AutoCorrectionEngine.Type = MATH_FRACTION;
AutoCorrectionEngine.props = {type: SKEWED_FRACTION};
this.Type = MATH_FRACTION;
this.props = {type: NO_BAR_FRACTION};
CurPos--;
break;
}
else if ('^' === Element.Text)
else if ( 0x2592 === Element.Text.charCodeAt(0) )// /of просто пропускаем
{
TempElements.Type = DEGREE_SUPERSCRIPT;
AutoCorrectionEngine.Kind = DEGREE_SUPERSCRIPT;
AutoCorrectionEngine.Type = MATH_DEGREE;
bOf = true;
CurPos--;
break;
}
else if ('_' === Element.Text)
else if (q_aMathAutoCorrectControlAggregationCodes[Element.Text.charCodeAt(0)]) //sum
{
TempElements.Type = DEGREE_SUBSCRIPT;
AutoCorrectionEngine.Kind = DEGREE_SUBSCRIPT;
AutoCorrectionEngine.Type = MATH_DEGREE;
//введены символы _ ^ + -
if (this.ActionElement.Type != para_Math_Composition && (this.ActionElementCode == 0x005E || this.ActionElementCode == 0x005F|| this.ActionElementCode == 0x002B || this.ActionElementCode == 0x002D))
return false;
this.chr = Element.Text;
this.Type = MATH_NARY;
CurPos--;
break;
}
else if ( 0x00A6 === Element.Text.charCodeAt(0) )
else if ( ' ' === Element.Text && !bCloseBrk)
break;
else if (g_aMathAutoCorrectTriggerCharCodes[Element.Text.charCodeAt(0)] && bOpenBrk && bCloseBrk)
break;
else if (g_aMathAutoCorrectFracCharCodes[Element.Text.charCodeAt(0)])
{
AutoCorrectionEngine.Type = MATH_FRACTION;
AutoCorrectionEngine.props = {type: NO_BAR_FRACTION};
CurPos--;
if (CurPos-1 > 0) // \sum_-\infty
{
var Elem = this.Elements[CurPos-1];
if ( para_Math_Text == Elem.Type && ('_' == Elem.Text || '^' == Elem.Text))
{
TempElements.splice(0, 0, Element);
TempElementsPos.splice(0, 0, CurPos);
}
else if (bCloseBrk) // \sum_(--)
{
TempElements.splice(0, 0, Element);
TempElementsPos.splice(0, 0, CurPos);
}
else if (!bCloseBrk && !bOf ) // \sum_--
break;
}
else if (g_aMathAutoCorrectTriggerCharCodes[Element.Text.charCodeAt(0)] && bOpenBrk && bCloseBrk)
else
break;
}
else if (q_aMathAutoCorrectControlCharCodes[Element.Text.charCodeAt(0)])
break;
else
{
TempElements.splice(0, 0, Element);
TempElementsPos.splice(0, 0, CurPos);
}
CurPos--;
}
......@@ -5559,80 +6328,104 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
bCloseBrk = false;
while (CurPos >= 0)
{
var Element = AutoCorrectionEngine.Elements[CurPos];
if (this.Type == MATH_NARY && TempElements.length == 0)
break;
var Element = this.Elements[CurPos];
if (undefined === Element.Text)
{
if (Element.Element.kind == MATH_GROUP_CHARACTER && AutoCorrectionEngine.Type == MATH_DEGREE)
if (Element.Element.kind == MATH_GROUP_CHARACTER && this.Type == MATH_DEGREE)
{
if ( DEGREE_SUPERSCRIPT == AutoCorrectionEngine.Kind )
AutoCorrectionEngine.props = {type: LIMIT_UP};
else if ( DEGREE_SUBSCRIPT == AutoCorrectionEngine.Kind )
AutoCorrectionEngine.props = {type: LIMIT_LOW};
AutoCorrectionEngine.Type = MATH_LIMIT;
if ( DEGREE_SUPERSCRIPT == this.Kind )
this.props = {type: LIMIT_UP};
else if ( DEGREE_SUBSCRIPT == this.Kind )
this.props = {type: LIMIT_LOW};
this.Type = MATH_LIMIT;
TempElements2.splice(0, 0, Element);
break;
}
else
TempElements2.splice(0, 0, Element);
}
else if ('(' === Element.Text)
else if (Element.Text === ')')
{
if (!bCloseBrk)
break;//return false;
if (bOpenBrk)
if (bOpenBrk || TempElements2.length > 0)
break;
TempElements2.splice(0, 0, Element);
bOpenBrk = true;
bCloseBrk = true;
}
else if (')' === Element.Text)
else if (Element.Text === '(')
{
if (!bCloseBrk)
break;
if (bOpenBrk)
break;
TempElements2.splice(0, 0, Element);
bCloseBrk = true;
bOpenBrk = true;
}
else if ('_' === Element.Text)
{
if (TempElements2.length == 0)
if ( this.Type == MATH_DEGREE && TempElements.Type == DEGREE_SUBSCRIPT)
break;
TempElements2.Type = DEGREE_SUBSCRIPT;
AutoCorrectionEngine.Kind = DEGREE_SubSup;
AutoCorrectionEngine.Type = MATH_DEGREESubSup;
this.Kind = DEGREE_SubSup;
this.Type = MATH_DEGREESubSup;
CurPos--;
break;
}
else if ('^' === Element.Text)
{
if (TempElements2.length == 0)
if ( this.Type == MATH_DEGREE && TempElements.Type == DEGREE_SUPERSCRIPT)
break;
TempElements2.Type = DEGREE_SUPERSCRIPT;
AutoCorrectionEngine.Kind = DEGREE_SubSup;
AutoCorrectionEngine.Type = MATH_DEGREESubSup;
this.Kind = DEGREE_SubSup;
this.Type = MATH_DEGREESubSup;
CurPos--;
break;
}
/*else if ( 0x25AD === Element.Text.charCodeAt(0) ) //borderbox
else if ( 0x24AD === Element.Text.charCodeAt(0)) // знак корня
{
AutoCorrectionEngine.Type = MATH_BORDER_BOX;
CurPos--;
this.Type = MATH_RADICAL;
break;
}
else if ( 0x25A1 === Element.Text.charCodeAt(0) ) //box
{
AutoCorrectionEngine.Type = MATH_BOX;
CurPos--;
break;
}*/
//если это элемент для Nary
else if (q_aMathAutoCorrectControlAggregationCodes[Element.Text.charCodeAt(0)]) //sum
{
AutoCorrectionEngine.chr = Element.Text;
AutoCorrectionEngine.Type = MATH_NARY;
CurPos--;
//введены символы _ ^ + -
if ((this.ActionElement.Type == para_Math_Text && (this.ActionElementCode == 0x005E || this.ActionElementCode == 0x005F))
|| (g_aMathAutoCorrectFracCharCodes[this.ActionElementCode] && TempElements.length == 0)) // \int_-
return false;
this.chr = Element.Text;
this.Type = MATH_NARY;
//CurPos--;
break;
}
else if (Element.Text === '/')
break;
else if ('@' === Element.Text || '&' === Element.Text )
break;
else if (g_aMathAutoCorrectTriggerCharCodes[Element.Text.charCodeAt(0)] && bOpenBrk && bCloseBrk)
break;
else if (' ' === Element.Text && !bCloseBrk)
break;
else if (g_aMathAutoCorrectFracCharCodes[Element.Text.charCodeAt(0)])
{
if (CurPos-1 > 0) // \sum_-\infty
{
var Elem = this.Elements[CurPos-1];
if ( para_Math_Text == Elem.Type && ('_' == Elem.Text || '^' == Elem.Text))
TempElements2.splice(0, 0, Element);
else if (bCloseBrk) // \sum_(--)
TempElements2.splice(0, 0, Element);
else if (!bCloseBrk && !bOf ) // \sum_--
break;
else if (!bCloseBrk && bOf) // \root n+a\of 2
TempElements2.splice(0, 0, Element);
}
else
break;
}
else if (q_aMathAutoCorrectControlCharCodes[Element.Text.charCodeAt(0)])
break;
else
......@@ -5641,15 +6434,38 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
CurPos--;
}
bOpenBrk = false;
bCloseBrk = false;
var TempElements3 = [];
if (AutoCorrectionEngine.Type == MATH_DEGREESubSup)
if (this.Type == MATH_DEGREESubSup)
{
var FracCharCodes = false;
while (CurPos >= 0)
{
var Element = AutoCorrectionEngine.Elements[CurPos];
if (undefined === Element.Text)
var Element = this.Elements[CurPos];
if (Element.Type != para_Math_Composition && q_aMathAutoCorrectControlAggregationCodes[Element.Text.charCodeAt(0)]) //sum
{
//введены символы _ ^ + -
if ((this.ActionElement.Type == para_Math_Text && (this.ActionElementCode == 0x005E || this.ActionElementCode == 0x005F))
|| (g_aMathAutoCorrectFracCharCodes[this.ActionElementCode] && TempElements.length == 0)) // \int_-
return false;
this.chr = Element.Text;
this.Type = MATH_NARY;
//CurPos--;
break;
}
else if (para_Math_Composition === Element.Type)
{
TempElements3.splice(0, 0, Element);
}
else if (g_MathRightBracketAutoCorrectCharCodes[Element.Text.charCodeAt(0)])
{
TempElements3.splice(0, 0, Element);
else if ('(' === Element.Text)
bCloseBrk = true;
FracCharCodes = true;
}
else if (g_MathLeftBracketAutoCorrectCharCodes[Element.Text.charCodeAt(0)])
{
if (!bCloseBrk)
return false;
......@@ -5658,116 +6474,173 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
TempElements3.splice(0, 0, Element);
bOpenBrk = true;
}
else if (')' === Element.Text)
else if ('_' === Element.Text)
{
TempElements3.splice(0, 0, Element);
bCloseBrk = true;
if ( this.Type == MATH_DEGREE && TempElements2.Type == DEGREE_SUBSCRIPT)
break;
TempElements3.Type = DEGREE_SUBSCRIPT;
//CurPos--;
if (CurPos >= 1)
{
var Elem = this.Elements[CurPos-1];
if (Elem.Type != para_Math_Composition && q_aMathAutoCorrectControlAggregationCodes[Elem.Text.charCodeAt(0)])
{
this.chr = Elem.Text;
this.Type = MATH_NARY;
CurPos--;
break;
}
else if ('@' === Element.Text || '&' === Element.Text )
else
break;
else if (g_aMathAutoCorrectTriggerCharCodes[Element.Text.charCodeAt(0)])
}
}
else if ('^' === Element.Text)
{
if ( this.Type == MATH_DEGREE && TempElements2.Type == DEGREE_SUPERSCRIPT)
break;
else if (q_aMathAutoCorrectControlAggregationCodes[Element.Text.charCodeAt(0)]) //sum
TempElements3.Type = DEGREE_SUPERSCRIPT;
CurPos--;
if (CurPos > 0)
{
var Elem = this.Elements[CurPos];
if (Elem.Type != para_Math_Composition && q_aMathAutoCorrectControlAggregationCodes[Elem.Text.charCodeAt(0)])
{
AutoCorrectionEngine.chr = Element.Text;
AutoCorrectionEngine.Type = MATH_NARY;
this.chr = Elem.Text;
this.Type = MATH_NARY;
CurPos--;
break;
}
else
break;
}
}
else if ( ' ' == Element.Text)
{
if (FracCharCodes)
break;
else
return false;
}
else if (g_aMathAutoCorrectTriggerCharCodes[Element.Text.charCodeAt(0)])
{
TempElements3.splice(0, 0, Element);
FracCharCodes = true;
}
else
{
TempElements3.splice(0, 0, Element);
}
CurPos--;
}
}
if (AutoCorrectionEngine.Type == MATH_FRACTION)
if (this.Type == MATH_FRACTION)
{
//todo для нуля вставить плейсхолдер
if (TempElements2.length > 0)
{
var props = new CMathFractionPr();
props.Set_FromObject(AutoCorrectionEngine.props);
props.Set_FromObject(this.props);
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
var Fraction = new CFraction(props);
var DenMathContent = Fraction.Content[0];
var NumMathContent = Fraction.Content[1];
this.PackTextToContent(DenMathContent, TempElements2, AutoCorrectionEngine);
this.PackTextToContent(NumMathContent, TempElements, AutoCorrectionEngine);
this.PackTextToContent(DenMathContent, TempElements2, AutoCorrectionEngine, true);
this.PackTextToContent(NumMathContent, TempElements, AutoCorrectionEngine, true);
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos - 1;
AutoCorrectionEngine.RemoveCount = this.ElementsCount - CurPos - 1;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.RemoveCount++;
AutoCorrectionEngine.ReplaceContent.unshift(Fraction);
return true;
}
}
else if (AutoCorrectionEngine.Type == MATH_DEGREE)
else if (this.Type == MATH_DEGREE)
{
if ( 0x5E === AutoCorrectionEngine.ActionElement.value || 0x5F === AutoCorrectionEngine.ActionElement.value)
var ReplaceElem = null;
if (CanMakeAutoCorrect && AutoCorrectionEngine.ReplaceContent.length>0 && AutoCorrectionEngine.ReplaceContent[0].Content.length>0)
ReplaceElem = AutoCorrectionEngine.ReplaceContent[0].Content[0].value;
// + - ^ _
if ( (CanMakeAutoCorrect && !g_aMathAutoCorrectFracCharCodes[ReplaceElem]) // x_i\times
|| !g_aMathAutoCorrectFracCharCodes[this.ActionElementCode])
return false;
else if (TempElements2.length > 0)
else
{
//this.ReplaceAutoCorrect(AutoCorrectionEngine, bCursorStepRight);
var props = new CMathDegreePr();
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
props.type = AutoCorrectionEngine.Kind;
props.type = this.Kind;
var oDegree = new CDegree(props)
var BaseContent = oDegree.Content[0];
var IterContent = oDegree.Content[1];
this.PackTextToContent(BaseContent, TempElements2, AutoCorrectionEngine);
this.PackTextToContent(IterContent, TempElements, AutoCorrectionEngine);
this.PackTextToContent(BaseContent, TempElements2, AutoCorrectionEngine, false);
this.PackTextToContent(IterContent, TempElements, AutoCorrectionEngine, true);
AutoCorrectionEngine.RemoveCount += this.ElementsCount - CurPos - 1;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.RemoveCount++;
if (CanMakeAutoCorrect)
AutoCorrectionEngine.RemoveCount += ElementsCount - CurPos - 1;
else
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos - 1;
AutoCorrectionEngine.ReplaceContent.unshift(oDegree);
return true;
}
}
else if (AutoCorrectionEngine.Type == MATH_DEGREESubSup)
else if (this.Type == MATH_DEGREESubSup)
{
if ( 0x5E === AutoCorrectionEngine.ActionElement.value || 0x5F === AutoCorrectionEngine.ActionElement.value)
if ( 0x5E === this.ActionElementCode || 0x5F === this.ActionElementCode)
return false;
else if (TempElements2.length > 0 || TempElements3.length > 0)
{
if (TempElements3.length === 0)
return false;
else
{
var props = new CMathDegreePr();
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
props.type = AutoCorrectionEngine.Kind;
props.type = this.Kind;
var oDegree = new CDegreeSubSup(props)
var BaseContent = oDegree.Content[0];
var IterUpContent = oDegree.Content[1];
var IterDnContent = oDegree.Content[2];
var IterDnContent = oDegree.Content[1];
var IterUpContent = oDegree.Content[2];
if (TempElements.Type == DEGREE_SUPERSCRIPT)
{
this.PackTextToContent(IterUpContent, TempElements2, AutoCorrectionEngine);
this.PackTextToContent(IterDnContent, TempElements, AutoCorrectionEngine);
this.PackTextToContent(IterUpContent, TempElements2, AutoCorrectionEngine, true);
this.PackTextToContent(IterDnContent, TempElements, AutoCorrectionEngine, true);
}
else if (TempElements.Type == DEGREE_SUBSCRIPT)
{
this.PackTextToContent(IterUpContent, TempElements, AutoCorrectionEngine);
this.PackTextToContent(IterDnContent, TempElements2, AutoCorrectionEngine);
this.PackTextToContent(IterUpContent, TempElements, AutoCorrectionEngine, true);
this.PackTextToContent(IterDnContent, TempElements2, AutoCorrectionEngine, true);
}
this.PackTextToContent(BaseContent, TempElements3, AutoCorrectionEngine);
var BaseElems = [TempElements3[TempElements3.length-1]];
this.PackTextToContent(BaseContent, BaseElems, AutoCorrectionEngine, true);
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos - 1;
AutoCorrectionEngine.RemoveCount += this.ElementsCount - CurPos - TempElements3.length;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.RemoveCount++;
AutoCorrectionEngine.ReplaceContent.unshift(oDegree);
return true;
}
}
else if (AutoCorrectionEngine.Type == MATH_RADICAL)
}
else if (this.Type == MATH_RADICAL)
{
if (!g_aMathAutoCorrectFracCharCodes[this.ActionElementCode]) // \sqrt(a+b)^
return false;
var props = new CMathRadicalPr();
if (TempElements2.length > 0)
props.degHide = 0;
......@@ -5779,16 +6652,23 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
var Base = Radical.getBase();
var Degree = Radical.getDegree();
this.PackTextToContent(Base, TempElements, AutoCorrectionEngine);
this.PackTextToContent(Base, TempElements, AutoCorrectionEngine, true);
if (!props.degHide)
this.PackTextToContent(Degree, TempElements2, AutoCorrectionEngine);
{
if (bOf)
this.PackTextToContent(Degree, TempElements2, AutoCorrectionEngine, false);
else
this.PackTextToContent(Degree, TempElements2, AutoCorrectionEngine, true);
}
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos ;
AutoCorrectionEngine.RemoveCount = this.ElementsCount - CurPos;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.RemoveCount++;
AutoCorrectionEngine.ReplaceContent.unshift(Radical);
return true;
}
else if (AutoCorrectionEngine.Type == MATH_BORDER_BOX)
else if (this.Type == MATH_BORDER_BOX)
{
var props = {};
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
......@@ -5796,13 +6676,15 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
var Base = BorderBox.getBase();
this.PackTextToContent(Base, TempElements, AutoCorrectionEngine);
this.PackTextToContent(Base, TempElements, AutoCorrectionEngine, true);
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos ;
AutoCorrectionEngine.RemoveCount = this.ElementsCount - CurPos ;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.RemoveCount++;
AutoCorrectionEngine.ReplaceContent.unshift(BorderBox);
return true;
}
else if (AutoCorrectionEngine.Type == MATH_BOX)
else if (this.Type == MATH_BOX)
{
var props = {};
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
......@@ -5810,17 +6692,62 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
var Base = Box.getBase();
this.PackTextToContent(Base, TempElements, AutoCorrectionEngine);
this.PackTextToContent(Base, TempElements, AutoCorrectionEngine, true);
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos - 1;
AutoCorrectionEngine.RemoveCount += this.ElementsCount - CurPos;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.RemoveCount++;
AutoCorrectionEngine.ReplaceContent.unshift(Box);
return true;
}
else if (AutoCorrectionEngine.Type == MATH_NARY)
else if (this.Type == MATH_NARY)
{
if ( this.ActionElementCode == 0x005C) //slash
return false;
if (bOf && this.CanPackToDelimiter(TempElements))
{
this.BrAccount.nLPos = TempElementsPos[0];
this.BrAccount.nRPos = TempElementsPos[TempElements.length - 1];
this.AutoCorrectDelimiter (AutoCorrectionEngine, CanMakeAutoCorrect)
return true;
}
var props = {};
if (TempElements.Type == DEGREE_SUPERSCRIPT)
{
if (TempElements2.length == 0)
props.subHide = true;
if (TempElements.length == 0)
props.supHide = true;
}
else if (TempElements.Type == DEGREE_SUBSCRIPT)
{
if (TempElements.length == 0)
props.subHide = true;
if (TempElements2.length == 0)
props.supHide = true;
}
else
{
if (TempElements2.Type == DEGREE_SUPERSCRIPT)
{
if (TempElements2.length == 0)
props.supHide = true;
if (TempElements3.length == 0)
props.subHide = true;
}
else
{
if (TempElements3.length == 0)
props.supHide = true;
if (TempElements2.length == 0)
props.subHide = true;
}
}
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
props.chr = AutoCorrectionEngine.chr.charCodeAt(0);
props.chr = this.chr.charCodeAt(0);
var oNary = new CNary(props);
var oSub = oNary.getLowerIterator();
......@@ -5829,131 +6756,118 @@ CMathContent.prototype.private_CanAutoCorrectEquation = function(AutoCorrectionE
if (TempElements.Type == DEGREE_SUPERSCRIPT)
{
this.PackTextToContent(oSub, TempElements2, AutoCorrectionEngine);
this.PackTextToContent(oSup, TempElements, AutoCorrectionEngine);
this.PackTextToContent(oSub, TempElements2, AutoCorrectionEngine, true);
this.PackTextToContent(oSup, TempElements, AutoCorrectionEngine, true);
}
else if (TempElements.Type == DEGREE_SUBSCRIPT)
{
this.PackTextToContent(oSub, TempElements, AutoCorrectionEngine);
this.PackTextToContent(oSup, TempElements2, AutoCorrectionEngine);
}
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos - 1;
AutoCorrectionEngine.ReplaceContent.unshift(oNary);
return true;
this.PackTextToContent(oSub, TempElements, AutoCorrectionEngine, true);
this.PackTextToContent(oSup, TempElements2, AutoCorrectionEngine, true);
}
/*else if (AutoCorrectionEngine.Type == MATH_LIMIT)
else
{
var props = {type: LIMIT_LOW};
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
var oLimit = new CLimit(props);
if (TempElements.Type == DEGREE_SUPERSCRIPT)
this.PackTextToContent(oBase, TempElements, AutoCorrectionEngine, true);
if (TempElements2.Type == DEGREE_SUPERSCRIPT)
{
this.PackTextToContent(oSub, TempElements2, AutoCorrectionEngine);
this.PackTextToContent(oSup, TempElements, AutoCorrectionEngine);
this.PackTextToContent(oSup, TempElements2, AutoCorrectionEngine, true);
this.PackTextToContent(oSub, TempElements3, AutoCorrectionEngine, true);
}
else if (TempElements.Type == DEGREE_SUBSCRIPT)
else
{
this.PackTextToContent(oSub, TempElements, AutoCorrectionEngine);
this.PackTextToContent(oSup, TempElements2, AutoCorrectionEngine);
this.PackTextToContent(oSup, TempElements3, AutoCorrectionEngine, true);
this.PackTextToContent(oSub, TempElements2, AutoCorrectionEngine, true);
}
}
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos - 1;
AutoCorrectionEngine.RemoveCount += this.ElementsCount - CurPos ;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.RemoveCount++;
AutoCorrectionEngine.ReplaceContent.unshift(oNary);
return true;
}*/
else if (AutoCorrectionEngine.Type == MATH_GROUP_CHARACTER)
}
else if (this.Type == MATH_GROUP_CHARACTER)
{
var props = AutoCorrectionEngine.props;
var props = this.props;
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
var oGroupChr = new CGroupCharacter(props);
var oBase = oGroupChr.getBase();
this.PackTextToContent(oBase, TempElements, AutoCorrectionEngine);
this.PackTextToContent(oBase, TempElements, AutoCorrectionEngine, true);
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos ;
AutoCorrectionEngine.RemoveCount += this.ElementsCount - CurPos ;
if (0x20 == this.ActionElementCode && this.BrAccount.LBracket && this.BrAccount.RBracket && CurPos != 0)
AutoCorrectionEngine.RemoveCount++;
AutoCorrectionEngine.ReplaceContent.unshift(oGroupChr);
return true;
}
else if (AutoCorrectionEngine.Type == MATH_BAR)
else if (this.Type == MATH_BAR)
{
var props = AutoCorrectionEngine.props;
var props = this.props;
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
var oBar = new CBar(props);
var oBase = oBar.getBase();
this.PackTextToContent(oBase, TempElements, AutoCorrectionEngine);
this.PackTextToContent(oBase, TempElements, AutoCorrectionEngine, true);
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos ;
AutoCorrectionEngine.RemoveCount += this.ElementsCount - CurPos ;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.RemoveCount++;
AutoCorrectionEngine.ReplaceContent.unshift(oBar);
return true;
}
else if (AutoCorrectionEngine.Type == MATH_LIMIT)
else if (this.Type == MATH_LIMIT)
{
var props = AutoCorrectionEngine.props;
var props = this.props;
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
var oLimit = new CLimit(props);
var oBase = oLimit.getFName();
var oIter = oLimit.getIterator();
this.PackTextToContent(oBase, TempElements2, AutoCorrectionEngine);
this.PackTextToContent(oIter, TempElements, AutoCorrectionEngine);
this.PackTextToContent(oBase, TempElements2, AutoCorrectionEngine, true);
this.PackTextToContent(oIter, TempElements, AutoCorrectionEngine, true);
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos ;
AutoCorrectionEngine.RemoveCount += this.ElementsCount - CurPos ;
AutoCorrectionEngine.ReplaceContent.unshift(oLimit);
return true;
}
else if (AutoCorrectionEngine.Type == MATH_PHANTOM)
else if (this.Type == MATH_PHANTOM)
{
var props = AutoCorrectionEngine.props;
var props = this.props;
props.ctrPrp = AutoCorrectionEngine.TextPr.Copy();
var oPhantom = new CPhantom(props);
var oBase = oPhantom.getBase();
this.PackTextToContent(oBase, TempElements, AutoCorrectionEngine);
this.PackTextToContent(oBase, TempElements, AutoCorrectionEngine, true);
AutoCorrectionEngine.RemoveCount = ElementsCount - CurPos - 1;
AutoCorrectionEngine.RemoveCount += this.ElementsCount - CurPos ;
if (0x20 == this.ActionElementCode)
AutoCorrectionEngine.RemoveCount++;
AutoCorrectionEngine.ReplaceContent.unshift(oPhantom);
return true;
}
else if (this.Type == MATH_DELIMITER)
{
this.AutoCorrectDelimiter(AutoCorrectionEngine, CanMakeAutoCorrect);
return true;
}
return false;
};
CMathContent.prototype.PackTextToContent = function(Element, TempElements, AutoCorrectionEngine)
AutoCorrectionControl.prototype.CanPackToDelimiter = function(TempElements)
{
var len = TempElements.length;
if (len > 1 && TempElements[0].Text)
if (TempElements[0].Text === '(' && TempElements[len-1].Text === ')')
{
TempElements.splice(len-1,1);
TempElements.splice(0,1);
len -= 2 ;
}
for (var nPos = 0; nPos < len; nPos++)
{
if (undefined === TempElements[nPos].Text)
Element.Internal_Content_Add(nPos, TempElements[nPos].Element);
else
{
var MathRun = new ParaRun(this.ParaMath.Paragraph, true);
MathRun.Set_Pr(AutoCorrectionEngine.TextPr.Copy());
MathRun.Set_MathPr(AutoCorrectionEngine.MathPr.Copy());
if (len < 2)
return false;
if( TempElements[0].Type != para_Math_Composition && TempElements[0].Text === '(' && TempElements[len-1].Type != para_Math_Composition && TempElements[len-1].Text === ')')
return true;
var MathText = new CMathText();
MathText.add(TempElements[nPos].Text.charCodeAt(0));
MathRun.Add_ToContent(nPos, MathText);
Element.Internal_Content_Add(nPos, MathRun);
}
}
return false;
};
CMathContent.prototype.ReplaceAutoCorrect = function(AutoCorrectEngine, bCursorStepRight)
{
......@@ -6002,17 +6916,126 @@ CMathContent.prototype.ReplaceAutoCorrect = function(AutoCorrectEngine, bCursorS
}
};
function CMathBracketAcc()
{
this.LBracket = false;
this.RBracket = false;
this.Separator = false;
this.Counter = 0;
this.LPos = -1;
this.LRPos = -1;
this.RPos = -1;
this.RLPos = -1;
this.LBracket = null;
this.RBracket = null;
this.LBracketlvl1 = null;
this.RBracketlvl1 = null;
this.LBracketlvl2 = null;
this.RBracketlvl2 = null;
this.bSeparator = false;
this.nSepPos = -1;
this.nCounter = 0;
this.nLPos = -1;
this.nLLPos = -1;
this.nRPos = -1;
this.nRRPos = -1;
this.Elems = [];
this.SepArr = [];
}
CMathBracketAcc.prototype.Counted = function()
{
var len = this.Elems.length;
for (var i = 0; i < len; i++)
{
var oElem = this.Elems[i];
}
};
CMathBracketAcc.prototype.CorrectLeft = function(Element, nNum, nCode)
{
this.nCounter--;
if (this.nLPos > nNum)
{
this.nLLPos = nNum;
if (this.nRPos < 0)
{
this.nLPos = nNum;
this.LBracket = nCode;
if (nCode === 0x0028 || nCode === 0x3016 || nCode === 0x251C)
this.LBracketlvl1 = nCode;
else
this.LBracketlvl2 = nCode;
}
}
else
{
this.nLPos = nNum;
this.LBracket = nCode;
if (nCode === 0x0028 || nCode === 0x3016 || nCode === 0x251C)
this.LBracketlvl1 = nCode;
else
this.LBracketlvl2 = nCode;
}
};
CMathBracketAcc.prototype.CorrectLeftSeparate = function(Element, nNum, nCode)
{
this.SepArr.unshift(this.nLPos);
this.nLPos = nNum;
this.LBracket = nCode;
if (nCode === 0x0028 || nCode === 0x3016 || nCode === 0x251C)
this.LBracketlvl1 = nCode;
else
this.LBracketlvl2 = nCode;
};
CMathBracketAcc.prototype.CorrectRight = function(Element, nNum, nCode)
{
this.nCounter++;
if (nNum > this.nRPos)
{
this.nRRPos = nNum;
if (this.nRPos < 0)
{
this.nRPos = nNum;
this.RBracket = nCode;
if (nCode === 0x0029 || nCode === 0x2524 || nCode === 0x3017)
this.LBracketlvl1 = nCode;
else
this.LBracketlvl2 = nCode;
}
}
else
{
this.nRPos = nNum;
this.RBracket = nCode;
if (nCode === 0x0029 || nCode === 0x2524 || nCode === 0x3017)
this.LBracketlvl1 = nCode;
else
this.LBracketlvl2 = nCode;
}
};
CMathBracketAcc.prototype.Comparelvl1 = function()
{
var bRes = false;
if ((this.LBracket == 0x0028 && this.RBracket == 0x0029) ||
(this.LBracket == 0x3016 && this.RBracket == 0x3017) ||
(this.LBracket == 0x251C && this.RBracket == 0x2524))
bRes = true;
return bRes;
};
CMathBracketAcc.prototype.Compare = function()
{
var bRes = false;
if ((this.LBracket == 0x0028 && this.RBracket == 0x0029) ||
(this.LBracket == 0x005B && this.RBracket == 0x005D) ||
(this.LBracket == 0x007B && this.RBracket == 0x007D) ||
(this.LBracket == 0x007C && this.RBracket == 0x007C) ||
(this.LBracket == 0x2016 && this.RBracket == 0x2016) ||
(this.LBracket == 0x27E8 && this.RBracket == 0x232A) ||
(this.LBracket == 0x27E8 && this.RBracket == 0x27EB) ||
(this.LBracket == 0x27E6 && this.RBracket == 0x27E7) ||
(this.LBracket == 0x2308 && this.RBracket == 0x2309) ||
(this.LBracket == 0x230A && this.RBracket == 0x230B) ||
(this.LBracket == 0x3016 && this.RBracket == 0x3017) ||
(this.LBracket == 0x251C && this.RBracket == 0x2524))
bRes = true;
return bRes;
};
function CMathAutoCorrectEngine(Element)
{
this.ActionElement = Element; // Элемент на которотом срабатывает автодополнение
......@@ -6025,6 +7048,7 @@ function CMathAutoCorrectEngine(Element)
this.RemoveCount = 0;
this.ReplaceContent = [];
this.Shift = 0;
this.TextPr = null;
this.MathPr = null;
......@@ -6032,12 +7056,12 @@ function CMathAutoCorrectEngine(Element)
CMathAutoCorrectEngine.prototype.Add_Element = function(Element, ElementPos)
{
this.Elements.push({Element : Element, ElementPos : ElementPos});
this.Elements.push({Element : Element, ElementPos : ElementPos, Type:Element.Type});
};
CMathAutoCorrectEngine.prototype.Add_Text = function(Text, Run, Pos, ElementPos)
CMathAutoCorrectEngine.prototype.Add_Text = function(Text, Run, Pos, ElementPos, Type)
{
this.Elements.push({Text : Text, Run : Run, Pos : Pos, ElementPos : ElementPos});
this.Elements.push({Text : Text, Run : Run, Pos : Pos, ElementPos : ElementPos, Type : Type});
};
CMathAutoCorrectEngine.prototype.Get_ActionElement = function()
......@@ -6050,6 +7074,18 @@ CMathAutoCorrectEngine.prototype.Stop_CollectText = function()
this.CollectText = false;
};
var g_aAutoCorrectMathFuncSymbols =
[
'sin', 'sec', 'asin', 'asec', 'arcsin', 'arcsec',
'cos', 'csc', 'acos', 'acsc', 'arccos', 'arccsc',
'tan', 'cot', 'atan', 'acot', 'arctan', 'arccot',
'sinh', 'sech', 'asinh', 'asech', 'arcsinh', 'arcech',
'cosh', 'csch', 'acosh', 'acsch', 'arccosh', 'arccsch',
'tanh', 'coth', 'atanh', 'acoth', 'arctanh', 'arccoth',
'arg', 'det', 'exp', 'inf', 'lim', 'min',
'def', 'dim', 'gcd', 'ker', 'log', 'Pr',
'deg', 'erf', 'hom', 'lg', 'ln', 'max', 'sup'
];
var g_aAutoCorrectMathSymbols =
[
['!!', 0x203C],
......@@ -6281,6 +7317,7 @@ var g_aAutoCorrectMathSymbols =
['\\lambda', 0x03BB],
['\\Lambda', 0x039B],
['\\langle', 0x2329],
['\\\lbbrack', 0x27E6],
['\\lbrace', 0x007B],
['\\lbrack', 0x005B],
['\\lceil', 0x2308],
......@@ -6296,8 +7333,10 @@ var g_aAutoCorrectMathSymbols =
['\\leftrightarrow', 0x2194],
['\\Leftrightarrow', 0x21D4],
['\\leq', 0x2264],
['\\lvec', 0x20D0],
['\\lfloor', 0x230A],
['\\ll', 0x226A],
['\\lvec', 0x20D6],
['\\mapsto', 0x21A6],
['\\matrix', 0x25A0],
['\\medsp', 0x205F],
......@@ -6360,9 +7399,11 @@ var g_aAutoCorrectMathSymbols =
['\\qdrt', 0x221C],
['\\quadratic', [0x0078, 0x003d, 0x0028, 0x002d, 0x0062, 0x00B1, 0x221A, 0x0020, 0x0028, 0x0062, 0x005e, 0x0032, 0x002d, 0x0034, 0x0061, 0x0063, 0x0029, 0x0029, 0x002f, 0x0032, 0x0061]],
['\\rangle', 0x232A],
['\\Rangle', 0x27EB],
['\\ratio', 0x2236],
['\\rbrace', 0x007D],
['\\rbrack', 0x005D],
['\\Rbrack', 0x27E7],
['\\rceil', 0x2309],
['\\rddots', 0x22F0],
['\\Re', 0x211C],
......@@ -6370,11 +7411,13 @@ var g_aAutoCorrectMathSymbols =
['\\rfloor', 0x230B],
['\\rho', 0x03C1],
['\\Rho', 0x03A1],
['\\rhvec', 0x20D1],
['\\right', 0x2524],
['\\rightarrow', 0x2192],
['\\Rightarrow', 0x21D2],
['\\rightharpoondown', 0x21C1],
['\\rightharpoonup', 0x21C0],
['\\root', 0x24AD],
['\\scripta', 0x1D4B6],
['\\scriptA', 0x1D49C],
['\\scriptb', 0x1D4B7],
......@@ -6509,13 +7552,15 @@ var g_aAutoCorrectMathSymbols =
['>=', 0x2265],
['>>', 0x226B]
];
//символы начала формулы
//символы начала формулы (корень, матрица...)
var q_aMathAutoCorrectControlCharCodes =
{
0x221A : 1, 0x221B : 1, 0x221C : 1, 0x25AD : 1, 0x25A1 : 1, 0x23DC : 1,
0x23E0 : 1, 0x23DD : 1, 0x00AF : 1, 0x033F : 1, 0x2581 : 1, 0x222E : 1,
0x23DF : 1, 0x23DE : 1
0x23DF : 1, 0x23DE : 1, 0x00D7 : 1, 0x24A9 : 1, 0x25A0 : 1, 0x24A8 : 1,
0x2588 : 1, 0x27E1 : 1, 0x2B04 : 1, 0x21F3 : 1
};
//символы для mathfunc (интеграл, сумма...)
var q_aMathAutoCorrectControlAggregationCodes =
{
0x2211 : 1, 0x220F : 1, 0x2210 : 1, 0x22C0 : 1, 0x2233 : 1,
......@@ -6523,13 +7568,64 @@ var q_aMathAutoCorrectControlAggregationCodes =
0x2A01 : 1, 0x2A02 : 1, 0x222B : 1, 0x222C : 1, 0x222D : 1,
0x2A0C : 1, 0x222E : 1, 0x222F : 1, 0x2230 : 1, 0x2232 : 1
};
//символы accent
var q_aMathAutoCorrectAccentCharCodes =
{
0x0305 : 1, 0x033F : 1, 0x0332 : 1, 0x0333 : 1, 0x0301 : 1,
0x0300 : 1, 0x20D7 : 1, 0x0306 : 1, 0x0302 : 1, 0x20E1 : 1,
0x20D1 : 1, 0x030C : 1, 0x0303 : 1, 0x20D6 : 1, 0x20D0 : 1,
0x0307 : 1, 0x0308 : 1, 0x20DB : 1, 0x20DC : 1, 0x2032 : 1,
0x2033 : 1, 0x2034 : 1, 0x2057 : 1
};
//симолы которые начинают автозамену groupchar
var g_aMathAutoCorrectTriggerEquationCharCodes =
{
0x23 : 1, 0x24 : 1, 0x25 : 1, 0x26 : 1, 0x29 : 1,
0x2A : 1, 0x2B : 1, 0x2C : 1, 0x2D : 1, 0x2E : 1, 0x2F : 1,
0x3A : 1, 0x3B : 1, 0x3C : 1, 0x3D : 1, 0x3E : 1, 0x3F : 1,
0x40 : 1, 0x5E : 1, 0x5F : 1,
0x60 : 1,
0x7E : 1
};
//left brackets
var g_MathLeftBracketAutoCorrectCharCodes =
{
/*0x28 : 1,*/ 0x5B : 1, 0x7B : 1, /*0x7C : 1,*/ 0x2016 : 1,
0x27E8 : 1, 0x2329 : 1, 0x27E6 : 1, 0x2308 : 1, 0x230A : 1,
0x3016 : 1, 0x251C : 1
};
var g_MathRightBracketAutoCorrectCharCodes =
{
/*0x29 : 1,*/ 0x5D : 1, 0x7D : 1, /*0x7C : 1,*/ 0x2016 : 1, 0x27E9 : 1,
0x232A : 1, 0x27EB : 1, 0x27E7 : 1, 0x2309 : 1, 0x230B : 1,
0x3017 : 1, 0x2524 : 1
};
//знаки (минус, сумма...)
var g_aMathAutoCorrectFracCharCodes =
{
0x20 : 1, /*0x21 : 1, 0x22 : 1, */0x23 : 1, /*0x24 : 1,*/ 0x25 : 1, 0x26 : 1,
/*0x27 : 1, */0x28 : 1, 0x29 : 1, 0x2A : 1, 0x2B : 1, 0x2C : 1, 0x2D : 1,
0x2E : 1, 0x2F : 1, 0x3A : 1, 0x3B : 1, 0x3C : 1, 0x3D : 1, 0x3E : 1,
0x3F : 1, 0x40 : 1, 0x5B : 1, /*0x5C : 1,*/ 0x5D : 1, /*0x5E : 1, 0x5F : 1,*/
0x60 : 1, 0x7B : 1, 0x7C : 1, 0x7D : 1, 0x7E : 1, /*0x2592 : 1*/
0xD7 : 1
};
var g_aMathAutoCorrectDegreeCharCodes =
{
/*0x20 : 1, 0x21 : 1, 0x22 : 1, */0x23 : 1, 0x24 : 1, 0x25 : 1, 0x26 : 1,
/*0x27 : 1, */0x28 : 1, 0x29 : 1, 0x2A : 1, 0x2B : 1, 0x2C : 1, 0x2D : 1,
0x2E : 1, /*0x2F : 1,*/ 0x3A : 1, 0x3B : 1, 0x3C : 1, 0x3D : 1, 0x3E : 1,
0x3F : 1, 0x40 : 1, 0x5B : 1, /*0x5C : 1,*/ 0x5D : 1, /*0x5E : 1, 0x5F : 1,*/
0x60 : 1, 0x7B : 1, 0x7C : 1, 0x7D : 1, 0x7E : 1, /*0x2592 : 1*/
0xD7 : 1
};
var g_aMathAutoCorrectTriggerCharCodes =
{
0x20 : 1, 0x21 : 1, 0x22 : 1, 0x23 : 1, 0x24 : 1, 0x25 : 1, 0x26 : 1,
0x27 : 1, 0x28 : 1, 0x29 : 1, 0x2A : 1, 0x2B : 1, 0x2C : 1, 0x2D : 1,
0x2E : 1, 0x2F : 1, 0x3A : 1, 0x3B : 1, 0x3C : 1, 0x3D : 1, 0x3E : 1,
0x3F : 1, 0x40 : 1, 0x5B : 1, 0x5C : 1, 0x5D : 1, 0x5E : 1, 0x5F : 1,
0x60 : 1, 0x7B : 1, 0x7C : 1, 0x7D : 1, 0x7E : 1
0x60 : 1, 0x7B : 1, 0x7C : 1, 0x7D : 1, 0x7E : 1, 0x2592 : 1
};
//--------------------------------------------------------export----------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment