Skip to content

Commit

Permalink
[de] Fix crash in some cases when adding math equation
Browse files Browse the repository at this point in the history
Remove changing the text case for text in math equations. Fix tests
  • Loading branch information
KirillovIlya committed Nov 29, 2024
1 parent b9a30dd commit 6de2076
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 146 deletions.
12 changes: 6 additions & 6 deletions tests/word/change-case/change-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ $(function () {
m.Add(oElement);
one.next();
}
};
}

QUnit.test("Sentence case math", function (assert)
{
Expand All @@ -272,7 +272,7 @@ $(function () {

assert.strictEqual(
m.Root.GetTextOfElement().GetText(),
"Abc. aaaaa/2",
"(abc. aaaaa)/2",
"Check sentence case"
);
});
Expand All @@ -293,7 +293,7 @@ $(function () {

assert.strictEqual(
m.Root.GetTextOfElement().GetText(),
'ABC/DEF+2_(XYZ.RTΔAAA+2)',
'abc/def+2_(xyz.rtδaaa+2)',
"Check upper case"
);
});
Expand All @@ -314,7 +314,7 @@ $(function () {

assert.strictEqual(
m.Root.GetTextOfElement().GetText(),
'abc/def+2_(xyz.rtδaaa+2)',
'ABC/DEF+2_(XYZ.RTΔAAA+2)',
"Check upper case"
);
});
Expand All @@ -335,7 +335,7 @@ $(function () {

assert.strictEqual(
m.Root.GetTextOfElement().GetText(),
'Abc/dEF+2_(xYz.rTδaAa+2)',
'aBC/Def+2_(XyZ.RtΔAaA+2)',
"Check ToggleCase case"
);
});
Expand All @@ -356,7 +356,7 @@ $(function () {

assert.strictEqual(
m.Root.GetTextOfElement().GetText(),
'Abc/Def+2_(Xyz.rtΔAaa+2)',
'aBC/Def+2_(XyZ.RtΔAaA+2)',
"Check CapitalizeWords case"
);
});
Expand Down
147 changes: 8 additions & 139 deletions word/Editor/ChangeCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
this.GlobalSettings = true;
this.CurrentParagraph = 0;
this.isAllinTable = true;
this.CurrentMathRun = null;
}
CChangeTextCaseEngine.prototype.ProcessParagraphs = function(arrParagraphs)
{
Expand Down Expand Up @@ -126,11 +125,7 @@

for (var nIndex = 0, nCount = this.WordBuffer.length; nIndex < nCount; ++nIndex)
{
var isMathRun = this.WordBuffer[nIndex].Run.IsMathRun();

var nCharCode = !isMathRun
? this.WordBuffer[nIndex].Run.GetElement(this.WordBuffer[nIndex].Pos).Value
: this.WordBuffer[nIndex].Run.GetElement(this.WordBuffer[nIndex].Pos).value;
var nCharCode = this.WordBuffer[nIndex].Run.GetElement(this.WordBuffer[nIndex].Pos).GetCodePoint();

var nLowerCode = String.fromCharCode(nCharCode).toLowerCase().charCodeAt(0);
var nUpperCode = String.fromCharCode(nCharCode).toUpperCase().charCodeAt(0);
Expand Down Expand Up @@ -179,12 +174,9 @@

var oRun = this.WordBuffer[nIndex].Run;
var nInRunPos = this.WordBuffer[nIndex].Pos;
var isMathRun = oRun.IsMathRun();

var nCharCode = !isMathRun
? oRun.GetElement(nInRunPos).Value
: oRun.GetElement(nInRunPos).value;


var nCharCode = oRun.GetElement(nInRunPos).GetCodePoint();

var nLowerCode = String.fromCharCode(nCharCode).toLowerCase().charCodeAt(0);
var nUpperCode = String.fromCharCode(nCharCode).toUpperCase().charCodeAt(0);

Expand All @@ -196,14 +188,7 @@
|| Asc.c_oAscChangeTextCaseType.UpperCase === nCaseType
|| (Asc.c_oAscChangeTextCaseType.CapitalizeWords === nCaseType && 0 === nIndex)))
{
var oNewText = !isMathRun
? new AscWord.CRunText(nUpperCode)
: new CMathText();

if (isMathRun)
oNewText.add(nUpperCode);

oRun.AddToContent(nInRunPos, oNewText, false);
oRun.AddToContent(nInRunPos, new AscWord.CRunText(nUpperCode), false);
oRun.RemoveFromContent(nInRunPos + 1, 1, false);
}
else if (nUpperCode === nCharCode
Expand All @@ -216,14 +201,7 @@
|| (Asc.c_oAscChangeTextCaseType.SentenceCase === nCaseType && bNeddToChange && !(this.StartSentence && 0 === nIndex))
))
{
var oNewText = !isMathRun
? new AscWord.CRunText(nUpperCode)
: new CMathText();

if (isMathRun)
oNewText.add(nLowerCode);

oRun.AddToContent(nInRunPos, oNewText, false);
oRun.AddToContent(nInRunPos, new AscWord.CRunText(nLowerCode), false);
oRun.RemoveFromContent(nInRunPos + 1, 1, false);
}
}
Expand Down Expand Up @@ -380,43 +358,6 @@
}
}
}
else if (oItem.IsMathText())
{
if (this.CurrentMathRun && this.CurrentMathRun !== oItem.GetMathBaseFirst())
{
this.currentSentence += this.word;
this.currentSentence += " ";
this.word = "";
this.CheckWords(this);
}

if (AscMath.MathLiterals.punct.SearchU(String.fromCharCode(oItem.value))
|| AscMath.MathLiterals.space.SearchU(String.fromCharCode(oItem.value))
|| AscMath.MathLiterals.operator.SearchU(String.fromCharCode(oItem.value))
|| AscMath.MathLiterals.operand.SearchU(String.fromCharCode(oItem.value)))
{
this.currentSentence += this.word;
this.currentSentence += " ";
this.word = "";
this.CheckWords(this);
}
else
{
if (isInSelection)
{
let nCharCode = oItem.value;
let nLowerCode = String.fromCharCode(nCharCode).toLowerCase().charCodeAt(0);
let nUpperCode = String.fromCharCode(nCharCode).toUpperCase().charCodeAt(0);

if (IsToSpace(nCharCode))
this.word += " ";
if (nLowerCode !== nCharCode || nUpperCode !== nCharCode)
this.word += String.fromCharCode(nCharCode);

this.CurrentMathRun = oItem.GetMathBaseFirst();
}
}
}
else
{
this.currentSentence += this.word;
Expand Down Expand Up @@ -446,7 +387,7 @@
if (undefined === nEndPos)
nEndPos = -1;

if (oRun.IsSelectionUse() && !oRun.IsMathRun())
if (oRun.IsSelectionUse())
{
nStartPos = oRun.GetSelectionStartPos();
nEndPos = oRun.GetSelectionEndPos();
Expand All @@ -457,17 +398,7 @@
oThis.CheckItemOnCollect(oRun.GetElement(nPos), nPos >= nStartPos && nPos < nEndPos);
}
});

if (this.CurrentMathRun)
{
this.currentSentence += this.word;
this.currentSentence += " ";
this.word = "";
this.CheckWords(this);

this.CurrentMathRun = null;
}


this.CurrentParagraph++;
}
};
Expand Down Expand Up @@ -518,40 +449,6 @@
}
}
}
else if (oItem.IsMathText())
{
let strMathText = String.fromCharCode(oItem.value);

if (this.CurrentMathRun && this.CurrentMathRun !== oItem.GetMathBaseFirst())
{
this.FlushWord();
this.SetStartSentence(true);
}

if (AscMath.MathLiterals.punct.SearchU(strMathText)
|| AscMath.MathLiterals.operand.SearchU(strMathText)
|| AscMath.MathLiterals.operator.SearchU(strMathText))
{
this.FlushWord();
this.SetStartSentence(true);
}
else
{
if (!AscMath.MathLiterals.space.SearchU(strMathText))
this.AddLetter(oRun, nPos, true);
else
this.FlushWord();

let nCharCode = oItem.value;
if (33 === nCharCode || 63 === nCharCode || 46 === nCharCode)
this.SetStartSentence(true);
else
this.SetStartSentence(false);

this.CurrentMathRun = oItem.GetMathBaseFirst();
}

}
else
{
this.FlushWord();
Expand All @@ -574,34 +471,6 @@
for (let nPos = nStartPos; nPos < nEndPos; ++nPos)
{
let oItem = oRun.GetElement(nPos);

if (oItem.IsMathText())
{
let nCharCode = oItem.value;
let nLowerCode = String.fromCharCode(nCharCode).toLowerCase().charCodeAt(0);
let nUpperCode = String.fromCharCode(nCharCode).toUpperCase().charCodeAt(0);

if (nLowerCode !== nCharCode || nUpperCode !== nCharCode)
{
if (nLowerCode === nCharCode && (Asc.c_oAscChangeTextCaseType.ToggleCase === this.ChangeType || Asc.c_oAscChangeTextCaseType.UpperCase === this.ChangeType))
{
let oCMathText = new CMathText();
oCMathText.add(nUpperCode);

oRun.AddToContent(nPos, oCMathText, false);
oRun.RemoveFromContent(nPos + 1, 1, false);
}
else if (nUpperCode === nCharCode && (Asc.c_oAscChangeTextCaseType.ToggleCase === this.ChangeType || Asc.c_oAscChangeTextCaseType.LowerCase === this.ChangeType))
{
let oCMathText = new CMathText();
oCMathText.add(nLowerCode);

oRun.AddToContent(nPos, oCMathText, false);
oRun.RemoveFromContent(nPos + 1, 1, false);
}
}
}

if (!oItem.IsText())
continue;

Expand Down
3 changes: 3 additions & 0 deletions word/Math/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2337,6 +2337,9 @@ CMathBase.prototype.Recalculate_LineMetrics = function(PRS, ParaPr, _CurLine, _C
}
}
};
CMathBase.prototype.Math_UpdateLineMetrics = function(PRS, paraPr)
{
};
CMathBase.prototype.IsEmptyRange = function(nCurLine, nCurRange)
{
if (!this.bOneLine)
Expand Down
2 changes: 1 addition & 1 deletion word/Math/mathContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5076,7 +5076,7 @@ CMathContent.prototype.Recalculate_Range = function(PRS, ParaPr, Depth)
else
NumberingAdd = PrevRecalcInfo.NumberingAdd;

if(NumberingAdd)
if(NumberingAdd && PRS.RunRecalcInfoLast)
{
PRS.X = PRS.Recalculate_Numbering(Item, this, ParaPr, PRS.X);
PRS.RunRecalcInfoLast.NumberingAdd = false;
Expand Down

0 comments on commit 6de2076

Please sign in to comment.