From 6de207633666e76154c7d0c4cd44f3fc05a3f0ac Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Fri, 29 Nov 2024 16:47:56 +0300 Subject: [PATCH] [de] Fix crash in some cases when adding math equation Remove changing the text case for text in math equations. Fix tests --- tests/word/change-case/change-case.js | 12 +-- word/Editor/ChangeCase.js | 147 ++------------------------ word/Math/base.js | 3 + word/Math/mathContent.js | 2 +- 4 files changed, 18 insertions(+), 146 deletions(-) diff --git a/tests/word/change-case/change-case.js b/tests/word/change-case/change-case.js index dcec85eee8..2b4bc3548c 100644 --- a/tests/word/change-case/change-case.js +++ b/tests/word/change-case/change-case.js @@ -251,7 +251,7 @@ $(function () { m.Add(oElement); one.next(); } - }; + } QUnit.test("Sentence case math", function (assert) { @@ -272,7 +272,7 @@ $(function () { assert.strictEqual( m.Root.GetTextOfElement().GetText(), - "Abc. aaaaa/2", + "(abc. aaaaa)/2", "Check sentence case" ); }); @@ -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" ); }); @@ -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" ); }); @@ -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" ); }); @@ -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" ); }); diff --git a/word/Editor/ChangeCase.js b/word/Editor/ChangeCase.js index 3a6232992d..8a2d513fb9 100644 --- a/word/Editor/ChangeCase.js +++ b/word/Editor/ChangeCase.js @@ -74,7 +74,6 @@ this.GlobalSettings = true; this.CurrentParagraph = 0; this.isAllinTable = true; - this.CurrentMathRun = null; } CChangeTextCaseEngine.prototype.ProcessParagraphs = function(arrParagraphs) { @@ -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); @@ -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); @@ -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 @@ -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); } } @@ -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; @@ -446,7 +387,7 @@ if (undefined === nEndPos) nEndPos = -1; - if (oRun.IsSelectionUse() && !oRun.IsMathRun()) + if (oRun.IsSelectionUse()) { nStartPos = oRun.GetSelectionStartPos(); nEndPos = oRun.GetSelectionEndPos(); @@ -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++; } }; @@ -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(); @@ -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; diff --git a/word/Math/base.js b/word/Math/base.js index 298f949213..626e28ed09 100644 --- a/word/Math/base.js +++ b/word/Math/base.js @@ -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) diff --git a/word/Math/mathContent.js b/word/Math/mathContent.js index b4ba28e722..d6ea45bb41 100644 --- a/word/Math/mathContent.js +++ b/word/Math/mathContent.js @@ -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;