Skip to content

Commit

Permalink
Merge pull request 'fix/show-complexfield-code' (#625) from fix/show-…
Browse files Browse the repository at this point in the history
…complexfield-code into release/v8.3.0
  • Loading branch information
KirillovIlya committed Feb 2, 2025
2 parents bbd6dc1 + 0d64677 commit 5da1111
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 32 deletions.
17 changes: 17 additions & 0 deletions word/Editor/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -23689,6 +23689,23 @@ CDocument.prototype.GetCurrentComplexFields = function()

return oParagraph.GetCurrentComplexFields();
};
CDocument.prototype.ToggleComplexFieldCodes = function()
{
let fields = this.GetCurrentComplexFields();
if (fields.length <= 0)
return;

for (let i = 0; i < fields.length; ++i)
{
if (!fields[i].IsShowFieldCode())
{
fields[i].ToggleFieldCodes();
return;
}
}

fields[fields.length - 1].ToggleFieldCodes();
};
CDocument.prototype.IsFastCollaborationBeforeViewModeInReview = function()
{
return this.ViewModeInReview.isFastCollaboration;
Expand Down
35 changes: 33 additions & 2 deletions word/Editor/Paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -4702,11 +4702,16 @@ Paragraph.prototype.Add = function(Item)

if (Item.SetParagraph)
Item.SetParagraph(this);


let itemType = Item.GetType();
if ((para_Text === itemType || para_Space === itemType) && this.IsCurrentPosInComplexFieldCode())
Item = new ParaInstrText(Item.GetCodePoint());

switch (Item.Get_Type())
{
case para_Text:
case para_Space:
case para_InstrText:
case para_PageNum:
case para_Tab:
case para_Drawing:
Expand All @@ -4719,6 +4724,7 @@ Paragraph.prototype.Add = function(Item)
case para_ContinuationSeparator:
default:
{

// Элементы данного типа добавляем во внутренний элемент
this.Content[this.CurPos.ContentPos].Add(Item);

Expand Down Expand Up @@ -16825,6 +16831,14 @@ Paragraph.prototype.GetPermRangesByPos = function(paraPos)
this.LoadSelectionState(state);
return permRanges;
};
Paragraph.prototype.IsCurrentPosInComplexFieldCode = function()
{
let cfStatePos = this.GetCurrentComplexFields(true);
if (!cfStatePos.length)
return false;

return cfStatePos[cfStatePos.length - 1].IsFieldCode();
};
Paragraph.prototype.GetCurrentComplexFields = function(bReturnFieldPos)
{
var arrComplexFields = [];
Expand Down Expand Up @@ -19527,6 +19541,11 @@ CComplexFieldStatePos.prototype.IsEqual = function(oState)
&& oState.ComplexField
&& this.ComplexField.GetBeginChar() === oState.ComplexField.GetBeginChar());
};
CComplexFieldStatePos.prototype.IsShowFieldCode = function()
{
let beginChar = this.ComplexField ? this.ComplexField.GetBeginChar() : null;
return beginChar ? beginChar.IsShowFieldCode() : null;
};

//----------------------------------------------------------------------------------------------------------------------
// Классы для работы с курсором
Expand Down Expand Up @@ -19646,7 +19665,7 @@ CParagraphSearchPos.prototype.InitComplexFields = function(arrComplexFields)
};
CParagraphSearchPos.prototype.isComplexField = function()
{
return (this.ComplexFields.length > 0 ? true : false);
return (this.ComplexFields.length > 0);
};
CParagraphSearchPos.prototype.isComplexFieldCode = function()
{
Expand All @@ -19661,6 +19680,18 @@ CParagraphSearchPos.prototype.isComplexFieldCode = function()

return false;
};
CParagraphSearchPos.prototype.isHiddenComplexFieldPart = function()
{
for (let fieldIndex = 0, fieldCount = this.ComplexFields.length; fieldIndex < fieldCount; ++ fieldIndex)
{
let isFieldCode = this.ComplexFields[fieldIndex].IsFieldCode();
let isShowCode = this.ComplexFields[fieldIndex].IsShowFieldCode();
if (isFieldCode !== isShowCode)
return true;
}

return false;
};
CParagraphSearchPos.prototype.isComplexFieldValue = function()
{
if (!this.isComplexField() || this.isComplexFieldCode())
Expand Down
69 changes: 69 additions & 0 deletions word/Editor/Paragraph/ComplexField.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ function ParaFieldChar(Type, LogicDocument)
this.X = 0;
this.Y = 0;
this.PageAbs = 0;

this.showFieldCode = false;

this.numText = null;
this.textPr = null;
Expand Down Expand Up @@ -446,6 +448,32 @@ ParaFieldChar.prototype.FindNextFillingForm = function(isNext, isCurrent, isStar
else
return (this.IsEnd() && (!isCurrent || isNext) ? this.ComplexField : null);
};
ParaFieldChar.prototype.IsShowFieldCode = function()
{
return this.showFieldCode;
};
ParaFieldChar.prototype.SetShowFieldCode = function(isShow)
{
this.showFieldCode = isShow;
};
ParaFieldChar.prototype.MoveCursorToChar = function(isBefore)
{
let run = this.GetRun();
if (!run)
return;
let inRunPos = run.GetElementPosition(this);
if (-1 === inRunPos)
return;

if (this.LogicDocument)
this.LogicDocument.RemoveSelection();

if (false === isBefore)
inRunPos += 1

run.Make_ThisElementCurrent(false);
run.SetCursorPosition(inRunPos);
};

/**
* @constructor
Expand Down Expand Up @@ -522,6 +550,14 @@ ParaInstrText.prototype.GetValue = function()
{
return String.fromCharCode(this.Value);
};
ParaInstrText.prototype.GetCodePoint = function()
{
return this.Value;
};
ParaInstrText.prototype.GetCharCode = function()
{
return this.Value;
};
ParaInstrText.prototype.SetCharCode = function(CharCode)
{
this.Value = CharCode;
Expand Down Expand Up @@ -2117,6 +2153,39 @@ CComplexField.prototype.GetRelatedParagraphs = function()

return result;
};
CComplexField.prototype.IsShowFieldCode = function()
{
if (!this.IsValid())
return false;

return this.BeginChar.IsShowFieldCode();
};
CComplexField.prototype.ToggleFieldCodes = function()
{
let isShowFieldCode = !this.BeginChar.IsShowFieldCode();

this.BeginChar.SetShowFieldCode(isShowFieldCode);

let logicDocument = this.LogicDocument;
if (!logicDocument)
return;

let history = logicDocument.GetHistory();
let recalcData = history.getRecalcDataByElements([this.BeginChar.GetParagraph()]);
logicDocument.RecalculateWithParams(recalcData);

if (isShowFieldCode)
{
this.BeginChar.MoveCursorToChar(false);
}
else
{
if (this.SeparateChar)
this.SeparateChar.MoveCursorToChar(false);
else
this.EndChar.MoveCursorToChar(true);
}
};

function getRefInstruction(sBookmarkName, nType, bHyperlink, bAboveBelow, sSeparator)
{
Expand Down
14 changes: 13 additions & 1 deletion word/Editor/Paragraph/complex-field-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
*/
ParagraphComplexFieldStack.prototype.checkRunElement = function(element)
{
if ((this.isHiddenFieldContent() || this.isComplexFieldCode())
if ((this.isHiddenFieldContent() || this.isHiddenComplexFieldPart())
&& para_End !== element.Type
&& para_FieldChar !== element.Type)
return false;
Expand Down Expand Up @@ -218,6 +218,18 @@

return false;
};
ParagraphComplexFieldStack.prototype.isHiddenComplexFieldPart = function()
{
for (let fieldIndex = 0, fieldCount = this.CF.length; fieldIndex < fieldCount; ++ fieldIndex)
{
let isFieldCode = this.CF[fieldIndex].IsFieldCode();
let isShowCode = this.CF[fieldIndex].IsShowFieldCode();
if (isFieldCode !== isShowCode)
return true;
}

return false;
};
ParagraphComplexFieldStack.prototype.isCurrentComplexField = function()
{
for (let index = 0, count = this.CF.length; index < count; ++index)
Expand Down
2 changes: 1 addition & 1 deletion word/Editor/Paragraph/draw/highlight-draw-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
ParagraphHighlightDrawState.prototype.isComplexFieldHighlight = function()
{
return (this.complexFields.isComplexField()
&& !this.complexFields.isComplexFieldCode()
&& !this.complexFields.isHiddenComplexFieldPart()
&& this.complexFields.isCurrentComplexField()
&& !this.complexFields.isHyperlinkField());
};
Expand Down
12 changes: 12 additions & 0 deletions word/Editor/Paragraph_Recalculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4473,6 +4473,18 @@ CParagraphRecalculateStateInfo.prototype.isComplexFieldCode = function()

return false;
};
CParagraphRecalculateStateInfo.prototype.isHiddenComplexFieldPart = function()
{
for (let fieldIndex = 0, fieldCount = this.ComplexFields.length; fieldIndex < fieldCount; ++ fieldIndex)
{
let isFieldCode = this.ComplexFields[fieldIndex].IsFieldCode();
let isShowCode = this.ComplexFields[fieldIndex].IsShowFieldCode();
if (isFieldCode !== isShowCode)
return true;
}

return false;
};
CParagraphRecalculateStateInfo.prototype.processFieldCharAndCollectComplexField = function(oChar)
{
if (oChar.IsBegin())
Expand Down
Loading

0 comments on commit 5da1111

Please sign in to comment.