Fix addingFieldData for field in header/footer/footnotes etc.
This commit is contained in:
Ilya Kirillov
2026-02-06 16:16:32 +03:00
parent 92af72e3ea
commit 62e08dc78b
7 changed files with 33 additions and 6 deletions

View File

@ -368,6 +368,7 @@
return;
logicDocument.RemoveFromContent(0, logicDocument.GetElementsCount(), false);
logicDocument.GetFinalSectPr().RemoveAllHdrFtr();
}
function ClearParagraph(p)
{

View File

@ -74,6 +74,8 @@
Set_RulerState_Table : function() {},
scrollToTarget : function() {},
GetVisibleRegion : function() {return [{Page : 0, Y : 0}, {Page : 0, Y : 0}]},
IsFreezePage : function() {return false;},
Set_RulerState_HdrFtr : function() {},
};
drawingDocument.CanvasHit = document.createElement('canvas');
@ -173,6 +175,7 @@
editor.asc_haveSpaceAfterParagraph = AscCommon.DocumentEditorApi.prototype.asc_haveSpaceAfterParagraph.bind(editor);
editor.initCollaborativeEditing = AscCommon.DocumentEditorApi.prototype.initCollaborativeEditing.bind(editor);
editor.asc_PasteData = AscCommon.DocumentEditorApi.prototype.asc_PasteData.bind(editor);
editor.GoToHeader = AscCommon.DocumentEditorApi.prototype.GoToHeader.bind(editor);
editor.externalChartCollector = {
onUpdateExternalList: function () {},

View File

@ -114,6 +114,29 @@ $(function () {
});
QUnit.test("Test addin fields in header/footer", function (assert)
{
AscTest.ClearDocument();
MoveToNewParagraph();
let sectPr = logicDocument.GetFinalSectPr();
let header = AscTest.CreateDefaultHeader(sectPr);
header.Set_CurrentElement(false, 0);
logicDocument.Set_DocumentDefaultTab(35.45);
let addinFieldData = {"FieldId": "1", "Value": "Addin №1", "Content": "This is the first addin field"};
PluginsApi.pluginMethod_AddAddinField(addinFieldData);
logicDocument.RemoveSelection();
logicDocument.Document_UpdateInterfaceState();
let fields = PluginsApi.pluginMethod_GetAllAddinFields();
assert.strictEqual(fields.length, 1, "Check one addin field in header");
assert.strictEqual(fields[0].Value, "Addin №1", "Check Value");
assert.strictEqual(fields[0].Content, "This is the first addin field", "Check Content from header field");
});
QUnit.test("Test RemoveFieldWrapper", function(assert)
{
AscTest.ClearDocument();

View File

@ -14462,7 +14462,7 @@ CDocument.prototype.AddSectionBreak = function(sectionBreakType)
sectPr.Copy(curSectPr);
curSectPr.Set_Type(sectionBreakType);
curSectPr.SetPageNumStart(-1);
curSectPr.Clear_AllHdrFtr();
curSectPr.RemoveAllHdrFtr();
this.History.MinorChanges = false;

View File

@ -1761,7 +1761,7 @@ CComplexField.prototype.GetFieldValueText = function()
var oEndPos = oDocument.GetContentPosition(false);
oDocument.SetSelectionByContentPositions(oStartPos, oEndPos);
let result = oDocument.GetSelectedText();
let result = logicDocument ? logicDocument.GetSelectedText() : "";
if (state)
logicDocument.LoadDocumentState(state);

View File

@ -188,7 +188,7 @@ var section_footnote_RestartEachPage = 0x02;
if (Other.HaveLineNumbers())
this.SetLineNumbers(Other.GetLineNumbersCountBy(), Other.GetLineNumbersDistance(), Other.GetLineNumbersStart(), Other.GetLineNumbersRestart());
};
SectPr.prototype.Clear_AllHdrFtr = function()
SectPr.prototype.RemoveAllHdrFtr = function()
{
this.Set_Header_First(null);
this.Set_Header_Even(null);

View File

@ -7210,7 +7210,7 @@
oSectPr.Copy(oCurSectPr);
oCurSectPr.Set_Type(oSectPr.Type);
oCurSectPr.SetPageNumStart(-1);
oCurSectPr.Clear_AllHdrFtr();
oCurSectPr.RemoveAllHdrFtr();
oParagraph.private_GetImpl().Set_SectionPr(oSectPr);
return new ApiSection(oSectPr);
@ -11947,7 +11947,7 @@
oCurSectPr.Set_Type(oSectPr.Type);
oCurSectPr.SetPageNumStart(-1);
oCurSectPr.Clear_AllHdrFtr();
oCurSectPr.RemoveAllHdrFtr();
this.private_GetImpl().Set_SectionPr(oSectPr);
return true;