Commit 9c89ef15 authored by Ilya Kirillov's avatar Ilya Kirillov

Implemented moving the cursor through complex fields with left/right arrows.

parent 49473f06
...@@ -4446,6 +4446,8 @@ Paragraph.prototype.Get_PageStartPos = function(CurPage) ...@@ -4446,6 +4446,8 @@ Paragraph.prototype.Get_PageStartPos = function(CurPage)
}; };
Paragraph.prototype.Get_LeftPos = function(SearchPos, ContentPos) Paragraph.prototype.Get_LeftPos = function(SearchPos, ContentPos)
{ {
SearchPos.InitComplexFields(this.GetComplexFieldsByPos(ContentPos, true));
var Depth = 0; var Depth = 0;
var CurPos = ContentPos.Get(Depth); var CurPos = ContentPos.Get(Depth);
...@@ -4481,6 +4483,8 @@ Paragraph.prototype.Get_LeftPos = function(SearchPos, ContentPos) ...@@ -4481,6 +4483,8 @@ Paragraph.prototype.Get_LeftPos = function(SearchPos, ContentPos)
}; };
Paragraph.prototype.Get_RightPos = function(SearchPos, ContentPos, StepEnd) Paragraph.prototype.Get_RightPos = function(SearchPos, ContentPos, StepEnd)
{ {
SearchPos.InitComplexFields(this.GetComplexFieldsByPos(ContentPos, true));
var Depth = 0; var Depth = 0;
var CurPos = ContentPos.Get(Depth); var CurPos = ContentPos.Get(Depth);
...@@ -4517,6 +4521,8 @@ Paragraph.prototype.Get_RightPos = function(SearchPos, ContentPos, StepEnd) ...@@ -4517,6 +4521,8 @@ Paragraph.prototype.Get_RightPos = function(SearchPos, ContentPos, StepEnd)
}; };
Paragraph.prototype.Get_WordStartPos = function(SearchPos, ContentPos) Paragraph.prototype.Get_WordStartPos = function(SearchPos, ContentPos)
{ {
SearchPos.InitComplexFields(this.GetComplexFieldsByPos(ContentPos, true));
var Depth = 0; var Depth = 0;
var CurPos = ContentPos.Get(Depth); var CurPos = ContentPos.Get(Depth);
...@@ -4552,6 +4558,8 @@ Paragraph.prototype.Get_WordStartPos = function(SearchPos, ContentPos) ...@@ -4552,6 +4558,8 @@ Paragraph.prototype.Get_WordStartPos = function(SearchPos, ContentPos)
}; };
Paragraph.prototype.Get_WordEndPos = function(SearchPos, ContentPos, StepEnd) Paragraph.prototype.Get_WordEndPos = function(SearchPos, ContentPos, StepEnd)
{ {
SearchPos.InitComplexFields(this.GetComplexFieldsByPos(ContentPos, true));
var Depth = 0; var Depth = 0;
var CurPos = ContentPos.Get(Depth); var CurPos = ContentPos.Get(Depth);
...@@ -12306,7 +12314,7 @@ Paragraph.prototype.AddContentControl = function(nContentControlType) ...@@ -12306,7 +12314,7 @@ Paragraph.prototype.AddContentControl = function(nContentControlType)
return oContentControl; return oContentControl;
} }
}; };
Paragraph.prototype.GetCurrentComplexFields = function() Paragraph.prototype.GetCurrentComplexFields = function(bReturnFieldPos)
{ {
var arrComplexFields = []; var arrComplexFields = [];
...@@ -12317,7 +12325,12 @@ Paragraph.prototype.GetCurrentComplexFields = function() ...@@ -12317,7 +12325,12 @@ Paragraph.prototype.GetCurrentComplexFields = function()
{ {
var oComplexField = oInfo.ComplexFields[nIndex].ComplexField; var oComplexField = oInfo.ComplexFields[nIndex].ComplexField;
if (oComplexField.IsUse()) if (oComplexField.IsUse())
arrComplexFields.push(oComplexField); {
if (bReturnFieldPos)
arrComplexFields.push(oInfo.ComplexFields[nIndex]);
else
arrComplexFields.push(oComplexField);
}
} }
} }
...@@ -12325,11 +12338,19 @@ Paragraph.prototype.GetCurrentComplexFields = function() ...@@ -12325,11 +12338,19 @@ Paragraph.prototype.GetCurrentComplexFields = function()
for (var nIndex = 0; nIndex <= nEndPos; ++nIndex) for (var nIndex = 0; nIndex <= nEndPos; ++nIndex)
{ {
if (this.Content[nIndex].GetCurrentComplexFields) if (this.Content[nIndex].GetCurrentComplexFields)
this.Content[nIndex].GetCurrentComplexFields(arrComplexFields, nIndex === nEndPos); this.Content[nIndex].GetCurrentComplexFields(arrComplexFields, nIndex === nEndPos, bReturnFieldPos);
} }
return arrComplexFields; return arrComplexFields;
}; };
Paragraph.prototype.GetComplexFieldsByPos = function(oParaPos, bReturnFieldPos)
{
var oCurrentPos = this.Get_ParaContentPos(false);
this.Set_ParaContentPos(oParaPos, false, -1, -1, false);
var arrComplexFields = this.GetCurrentComplexFields(bReturnFieldPos);
this.Set_ParaContentPos(oCurrentPos, false, -1, -1, false);
return arrComplexFields;
};
var pararecalc_0_All = 0; var pararecalc_0_All = 0;
var pararecalc_0_None = 1; var pararecalc_0_None = 1;
...@@ -13121,7 +13142,7 @@ function CParagraphSearchPos() ...@@ -13121,7 +13142,7 @@ function CParagraphSearchPos()
this.CheckAnchors = false; this.CheckAnchors = false;
this.CheckComplexFields = false; this.ComplexFields = [];
} }
CParagraphSearchPos.prototype.SetCheckAnchors = function(bCheck) CParagraphSearchPos.prototype.SetCheckAnchors = function(bCheck)
{ {
...@@ -13131,25 +13152,100 @@ CParagraphSearchPos.prototype.IsCheckAnchors = function() ...@@ -13131,25 +13152,100 @@ CParagraphSearchPos.prototype.IsCheckAnchors = function()
{ {
return this.CheckAnchors; return this.CheckAnchors;
}; };
CParagraphSearchPos.prototype.SetCheckComplexFields = function(isCheck) CParagraphSearchPos.prototype.ProcessComplexFieldChar = function(nDirection, oFieldChar)
{ {
this.CheckComplexFields = isCheck; if (!oFieldChar || !oFieldChar.IsUse())
return;
if (nDirection > 0)
{
var oComplexField = oFieldChar.GetComplexField();
if (oFieldChar.IsBegin())
{
this.ComplexFields.push(new CComplexFieldStatePos(oComplexField, true));
}
else if (oFieldChar.IsSeparate())
{
for (var nIndex = 0, nCount = this.ComplexFields.length; nIndex < nCount; ++nIndex)
{
if (oComplexField === this.ComplexFields[nIndex].ComplexField)
{
this.ComplexFields[nIndex].SetFieldCode(false);
break;
}
}
}
else if (oFieldChar.IsEnd())
{
for (var nIndex = 0, nCount = this.ComplexFields.length; nIndex < nCount; ++nIndex)
{
if (oComplexField === this.ComplexFields[nIndex].ComplexField)
{
this.ComplexFields.splice(nIndex, 1);
break;
}
}
}
}
else
{
var oComplexField = oFieldChar.GetComplexField();
if (oFieldChar.IsEnd())
{
this.ComplexFields.push(new CComplexFieldStatePos(oComplexField, false));
}
else if (oFieldChar.IsSeparate())
{
for (var nIndex = 0, nCount = this.ComplexFields.length; nIndex < nCount; ++nIndex)
{
if (oComplexField === this.ComplexFields[nIndex].ComplexField)
{
this.ComplexFields[nIndex].SetFieldCode(true);
break;
}
}
}
else if (oFieldChar.IsBegin())
{
for (var nIndex = 0, nCount = this.ComplexFields.length; nIndex < nCount; ++nIndex)
{
if (oComplexField === this.ComplexFields[nIndex].ComplexField)
{
this.ComplexFields.splice(nIndex, 1);
break;
}
}
}
}
}; };
CParagraphSearchPos.prototype.IsCheckComplexFields = function() CParagraphSearchPos.prototype.InitComplexFields = function(arrComplexFields)
{ {
return this.CheckComplexFields; this.ComplexFields = arrComplexFields;
}; };
CParagraphSearchPos.prototype.ProcessComplexFieldChar = function(nDirection, oChar) CParagraphSearchPos.prototype.IsComplexField = function()
{ {
return (this.ComplexFields.length > 0 ? true : false);
}; };
CParagraphSearchPos.prototype.IsComplexFieldCode = function() CParagraphSearchPos.prototype.IsComplexFieldCode = function()
{ {
if (!this.IsComplexField())
return false;
for (var nIndex = 0, nCount = this.ComplexFields.length; nIndex < nCount; ++nIndex)
{
if (this.ComplexFields[nIndex].IsFieldCode())
return true;
}
return false; return false;
}; };
CParagraphSearchPos.prototype.IsComplexFieldValue = function() CParagraphSearchPos.prototype.IsComplexFieldValue = function()
{ {
return false; if (!this.IsComplexField() || this.IsComplexFieldCode())
return false;
return true;
}; };
function CParagraphSearchPosXY() function CParagraphSearchPosXY()
......
...@@ -2966,13 +2966,13 @@ CParagraphContentWithParagraphLikeContent.prototype.PreDelete = function() ...@@ -2966,13 +2966,13 @@ CParagraphContentWithParagraphLikeContent.prototype.PreDelete = function()
this.Content[nIndex].PreDelete(); this.Content[nIndex].PreDelete();
} }
}; };
CParagraphContentWithParagraphLikeContent.prototype.GetCurrentComplexFields = function(arrComplexFields, isCurrent) CParagraphContentWithParagraphLikeContent.prototype.GetCurrentComplexFields = function(arrComplexFields, isCurrent, isFieldPos)
{ {
var nEndPos = isCurrent ? this.State.ContentPos : this.Content.length - 1; var nEndPos = isCurrent ? this.State.ContentPos : this.Content.length - 1;
for (var nIndex = 0; nIndex <= nEndPos; ++nIndex) for (var nIndex = 0; nIndex <= nEndPos; ++nIndex)
{ {
if (this.Content[nIndex] && this.Content[nIndex].GetCurrentComplexFields) if (this.Content[nIndex] && this.Content[nIndex].GetCurrentComplexFields)
this.Content[nIndex].GetCurrentComplexFields(arrComplexFields, isCurrent && nIndex === nEndPos); this.Content[nIndex].GetCurrentComplexFields(arrComplexFields, isCurrent && nIndex === nEndPos, isFieldPos);
} }
}; };
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
......
...@@ -5527,12 +5527,25 @@ ParaRun.prototype.Get_LeftPos = function(SearchPos, ContentPos, Depth, UseConten ...@@ -5527,12 +5527,25 @@ ParaRun.prototype.Get_LeftPos = function(SearchPos, ContentPos, Depth, UseConten
{ {
var CurPos = true === UseContentPos ? ContentPos.Get(Depth) : this.Content.length; var CurPos = true === UseContentPos ? ContentPos.Get(Depth) : this.Content.length;
var isFieldCode = SearchPos.IsComplexFieldCode();
var isFieldValue = SearchPos.IsComplexFieldValue();
while (true) while (true)
{ {
CurPos--; CurPos--;
var Item = this.Content[CurPos]; var Item = this.Content[CurPos];
if (CurPos >= 0 && para_FieldChar === Item.Type)
{
SearchPos.ProcessComplexFieldChar(-1, Item);
isFieldCode = SearchPos.IsComplexFieldCode();
isFieldValue = SearchPos.IsComplexFieldValue();
}
if (CurPos >= 0 && isFieldCode)
continue;
if (CurPos < 0 || (!(para_Drawing === Item.Type && false === Item.Is_Inline() && false === SearchPos.IsCheckAnchors()) && !(para_FootnoteReference === Item.Type && true === Item.IsCustomMarkFollows()))) if (CurPos < 0 || (!(para_Drawing === Item.Type && false === Item.Is_Inline() && false === SearchPos.IsCheckAnchors()) && !(para_FootnoteReference === Item.Type && true === Item.IsCustomMarkFollows())))
break; break;
} }
...@@ -5548,6 +5561,9 @@ ParaRun.prototype.Get_RightPos = function(SearchPos, ContentPos, Depth, UseConte ...@@ -5548,6 +5561,9 @@ ParaRun.prototype.Get_RightPos = function(SearchPos, ContentPos, Depth, UseConte
{ {
var CurPos = ( true === UseContentPos ? ContentPos.Get(Depth) : 0 ); var CurPos = ( true === UseContentPos ? ContentPos.Get(Depth) : 0 );
var isFieldCode = SearchPos.IsComplexFieldCode();
var isFieldValue = SearchPos.IsComplexFieldValue();
var Count = this.Content.length; var Count = this.Content.length;
while (true) while (true)
{ {
...@@ -5563,6 +5579,17 @@ ParaRun.prototype.Get_RightPos = function(SearchPos, ContentPos, Depth, UseConte ...@@ -5563,6 +5579,17 @@ ParaRun.prototype.Get_RightPos = function(SearchPos, ContentPos, Depth, UseConte
var PrevItem = this.Content[CurPos - 1]; var PrevItem = this.Content[CurPos - 1];
var PrevItemType = PrevItem.Type; var PrevItemType = PrevItem.Type;
if (para_FieldChar === PrevItem.Type)
{
SearchPos.ProcessComplexFieldChar(1, PrevItem);
isFieldCode = SearchPos.IsComplexFieldCode();
isFieldValue = SearchPos.IsComplexFieldValue();
}
if (isFieldCode)
return;
if ((true !== StepEnd && para_End === PrevItemType) || (para_Drawing === PrevItemType && false === PrevItem.Is_Inline() && false === SearchPos.IsCheckAnchors()) || (para_FootnoteReference === PrevItemType && true === PrevItem.IsCustomMarkFollows())) if ((true !== StepEnd && para_End === PrevItemType) || (para_Drawing === PrevItemType && false === PrevItem.Is_Inline() && false === SearchPos.IsCheckAnchors()) || (para_FootnoteReference === PrevItemType && true === PrevItem.IsCustomMarkFollows()))
return; return;
...@@ -5576,6 +5603,16 @@ ParaRun.prototype.Get_RightPos = function(SearchPos, ContentPos, Depth, UseConte ...@@ -5576,6 +5603,16 @@ ParaRun.prototype.Get_RightPos = function(SearchPos, ContentPos, Depth, UseConte
var Item = this.Content[CurPos - 1]; var Item = this.Content[CurPos - 1];
var ItemType = Item.Type; var ItemType = Item.Type;
if (para_FieldChar === Item.Type)
{
SearchPos.ProcessComplexFieldChar(1, Item);
isFieldCode = SearchPos.IsComplexFieldCode();
isFieldValue = SearchPos.IsComplexFieldValue();
}
if (isFieldCode)
continue;
if (!(true !== StepEnd && para_End === ItemType) if (!(true !== StepEnd && para_End === ItemType)
&& !(para_Drawing === Item.Type && false === Item.Is_Inline()) && !(para_Drawing === Item.Type && false === Item.Is_Inline())
&& !(para_FootnoteReference === Item.Type && true === Item.IsCustomMarkFollows())) && !(para_FootnoteReference === Item.Type && true === Item.IsCustomMarkFollows()))
...@@ -9369,7 +9406,7 @@ ParaRun.prototype.GetLineByPosition = function(nPos) ...@@ -9369,7 +9406,7 @@ ParaRun.prototype.GetLineByPosition = function(nPos)
ParaRun.prototype.PreDelete = function() ParaRun.prototype.PreDelete = function()
{ {
}; };
ParaRun.prototype.GetCurrentComplexFields = function(arrComplexFields, isCurrent) ParaRun.prototype.GetCurrentComplexFields = function(arrComplexFields, isCurrent, isFieldPos)
{ {
var nEndPos = isCurrent ? this.State.ContentPos : this.Content.length; var nEndPos = isCurrent ? this.State.ContentPos : this.Content.length;
for (var nPos = 0; nPos < nEndPos; ++nPos) for (var nPos = 0; nPos < nEndPos; ++nPos)
...@@ -9378,15 +9415,40 @@ ParaRun.prototype.GetCurrentComplexFields = function(arrComplexFields, isCurrent ...@@ -9378,15 +9415,40 @@ ParaRun.prototype.GetCurrentComplexFields = function(arrComplexFields, isCurrent
if (oItem.Type !== para_FieldChar) if (oItem.Type !== para_FieldChar)
continue; continue;
if (oItem.IsBegin()) if (isFieldPos)
{ {
arrComplexFields.push(oItem.GetComplexField()); var oComplexField = oItem.GetComplexField();
if (oItem.IsBegin())
{
arrComplexFields.push(new CComplexFieldStatePos(oComplexField, true));
}
else if (oItem.IsSeparate())
{
if (arrComplexFields.length > 0)
{
arrComplexFields[arrComplexFields.length - 1].SetFieldCode(false)
}
}
else if (oItem.IsEnd())
{
if (arrComplexFields.length > 0)
{
arrComplexFields.splice(arrComplexFields.length - 1, 1);
}
}
} }
else if (oItem.IsEnd()) else
{ {
if (arrComplexFields.length > 0) if (oItem.IsBegin())
{ {
arrComplexFields.splice(arrComplexFields.length - 1, 1); arrComplexFields.push(oItem.GetComplexField());
}
else if (oItem.IsEnd())
{
if (arrComplexFields.length > 0)
{
arrComplexFields.splice(arrComplexFields.length - 1, 1);
}
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment