Don't clear content when converting a footnote to an endnote and vice versa
This commit is contained in:
Ilya Kirillov
2025-09-24 19:33:14 +03:00
parent a8b3a1c259
commit 85bfc098a2
3 changed files with 20 additions and 22 deletions

View File

@ -1408,7 +1408,7 @@ function CDocument(DrawingDocument, isMainLogicDocument)
this.CompileStyleOnLoad = false; // Компилировать ли принудительно стили во время загрузки
this.SmartParagraphSelection = true; // Выделять ли автоматически знак параграфа, когда все содержимое параграфа выделено
this.PreventPreDelete = false; // Заглушка на случай, когда удаляемые объекты, не удаляются, а переносятся
this.ClearNotesOnPreDelete = true; // Очищать ли сноски при удалении (выключаем, при сплите параграфа)
this.ClearNotesOnPreDelete = true; // Очищать ли сноски при удалении (выключаем, при сплите параграфа) // TODO: Объединить с PreventPreDelete
this.DrawTableMode = {
Start : false,

View File

@ -293,7 +293,8 @@
let logicDocument = paragraph ? paragraph.GetTopDocumentContent() : null;
if (!logicDocument
|| !(logicDocument instanceof AscWord.CDocument)
|| !logicDocument.IsDocumentEditor()
|| logicDocument.isPreventedPreDelete()
|| false === logicDocument.ClearNotesOnPreDelete)
return;

View File

@ -12143,6 +12143,15 @@ ParaRun.prototype.CopyTextFormContent = function(oRun)
*/
ParaRun.prototype.ConvertFootnoteType = function(isToFootnote, oStyles, oFootnote, oRef)
{
let _t = this;
function replaceRef(pos, newRef)
{
AscCommon.executeNoPreDelete(function(){
_t.RemoveFromContent(pos, 1);
_t.AddToContent(pos, newRef);
}, _t.GetLogicDocument());
}
var sRStyle = this.GetRStyle();
if (isToFootnote)
{
@ -12151,21 +12160,15 @@ ParaRun.prototype.ConvertFootnoteType = function(isToFootnote, oStyles, oFootnot
else if (sRStyle === oStyles.GetDefaultEndnoteReference())
this.SetRStyle(oStyles.GetDefaultFootnoteReference());
for (var nCurPos = 0, nCount = this.Content.length; nCurPos < nCount; ++nCurPos)
for (let nCurPos = 0, nCount = this.Content.length; nCurPos < nCount; ++nCurPos)
{
var oElement = this.Content[nCurPos];
let oElement = this.Content[nCurPos];
if (!oRef || oRef === oElement)
{
if (para_EndnoteReference === oElement.Type)
{
this.RemoveFromContent(nCurPos, 1);
this.AddToContent(nCurPos, new AscWord.CRunFootnoteReference(oFootnote, oElement.CustomMark));
}
replaceRef(nCurPos, new AscWord.CRunFootnoteReference(oFootnote, oElement.CustomMark));
else if (para_EndnoteRef === oElement.Type)
{
this.RemoveFromContent(nCurPos, 1);
this.AddToContent(nCurPos, new AscWord.CRunFootnoteRef(oFootnote));
}
replaceRef(nCurPos, new AscWord.CRunFootnoteRef(oFootnote));
}
}
}
@ -12176,21 +12179,15 @@ ParaRun.prototype.ConvertFootnoteType = function(isToFootnote, oStyles, oFootnot
else if (sRStyle === oStyles.GetDefaultFootnoteReference())
this.SetRStyle(oStyles.GetDefaultEndnoteReference());
for (var nCurPos = 0, nCount = this.Content.length; nCurPos < nCount; ++nCurPos)
for (let nCurPos = 0, nCount = this.Content.length; nCurPos < nCount; ++nCurPos)
{
var oElement = this.Content[nCurPos];
let oElement = this.Content[nCurPos];
if (!oRef || oRef === oElement)
{
if (para_FootnoteReference === oElement.Type)
{
this.RemoveFromContent(nCurPos, 1);
this.AddToContent(nCurPos, new AscWord.CRunEndnoteReference(oFootnote, oElement.CustomMark));
}
replaceRef(nCurPos, new AscWord.CRunEndnoteReference(oFootnote, oElement.CustomMark));
else if (para_FootnoteRef === oElement.Type)
{
this.RemoveFromContent(nCurPos, 1);
this.AddToContent(nCurPos, new AscWord.CRunEndnoteRef(oFootnote));
}
replaceRef(nCurPos, new AscWord.CRunEndnoteRef(oFootnote));
}
}
}