Commit 702b3bc2 authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander.Trofimov

Исправлены баги при drag-n-drop формулы внутри себя.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@58942 954022d7-b5bf-4e40-9824-e11837661b57
parent 9675e08a
......@@ -8746,12 +8746,12 @@ CDocument.prototype =
this.Selection_Remove();
var NewMathRun = MathRun.Split2(ParaNearPos.NearPos.ContentPos.Data[ParaNearPos.NearPos.ContentPos.Depth - 1]);
var NewMathRun = MathRun.Split(ParaNearPos.NearPos.ContentPos, ParaNearPos.Classes.length - 1);
var MathContent = ParaNearPos.Classes[ParaNearPos.Classes.length - 2];
var MathContentPos = MathContent.CurPos; // TODO: текущая позиция выставилась в функции Check_NearestPos
var MathContentPos = ParaNearPos.NearPos.ContentPos.Data[ParaNearPos.Classes.length - 2];
MathContent.Add_ToContent(MathContentPos + 1, NewMathRun);
MathContent.Insert_MathContent(Element.Content[0].Root, MathContentPos + 1);
MathContent.Insert_MathContent(Element.Content[0].Root, MathContentPos + 1, true);
this.Recalculate();
......
......@@ -228,10 +228,7 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText)
return false;
// Значит мы в каком-то элементе, тогда надо выделить данный элемент
var oParent = oContent.GetParent();
oParent.Select_WholeElement();
oParent.Select_ToRoot();
this.bSelectionUse = true;
oContent.ParentElement.Select_WholeElement();
return true;
}
......@@ -256,9 +253,7 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText)
}
else
{
oContent.Select_ElementByPos(nStartPos + 1);
oContent.Select_ToRoot();
this.bSelectionUse = true;
oContent.Select_ElementByPos(nStartPos + 1, true);
}
}
else //if (Direction < 0)
......@@ -281,9 +276,7 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText)
}
else
{
oContent.Select_ElementByPos(nStartPos - 1);
oContent.Select_ToRoot();
this.bSelectionUse = true;
oContent.Select_ElementByPos(nStartPos - 1, true);
}
}
}
......@@ -398,14 +391,7 @@ ParaMath.prototype.Clear_TextPr = function()
ParaMath.prototype.Check_NearestPos = function(ParaNearPos, Depth)
{
this.Selection_Remove();
this.Set_ParaContentPos(ParaNearPos.NearPos.ContentPos, Depth);
var oSelectedContent = this.GetSelectContent();
var oContent = oSelectedContent.Content;
ParaNearPos.Classes.push(oContent);
ParaNearPos.Classes.push(oContent.content[oContent.CurPos]);
this.Root.Check_NearestPos(ParaNearPos, Depth);
};
ParaMath.prototype.Get_DrawingObjectRun = function(Id)
......
......@@ -6003,6 +6003,25 @@ Paragraph.prototype =
this.Set_SelectionContentPos( StartPos, EndPos );
},
Select_Math : function(ParaMath)
{
for (var nPos = 0, nCount = this.Content.length; nPos < nCount; nPos++)
{
if (this.Content[nPos] === ParaMath)
{
this.Selection.Use = true;
this.Selection.StartManually = false;
this.Selection.EndManually = false;
this.Selection.StartPos = nPos;
this.Selection.EndPos = nPos;
this.Selection.Flag = selectionflag_Common;
this.Document_SetThisElementCurrent(false);
return;
}
}
},
Get_SelectionBounds : function()
{
var X0 = this.X, X1 = this.XLimit, Y = this.Y, Page = this.Get_StartPage_Absolute();
......
......@@ -109,17 +109,19 @@ ParaRun.prototype.Copy = function(Selected)
var StartPos = 0;
var EndPos = this.Content.length;
if ( true === Selected && true === this.State.Selection.Use )
if (true === Selected && true === this.State.Selection.Use)
{
StartPos = this.State.Selection.StartPos;
EndPos = this.State.Selection.EndPos;
if ( StartPos > EndPos )
if (StartPos > EndPos)
{
StartPos = this.State.Selection.EndPos;
EndPos = this.State.Selection.StartPos;
}
}
else if (true === Selected && true !== this.State.Selection.Use)
EndPos = -1;
for ( var CurPos = StartPos; CurPos < EndPos; CurPos++ )
{
......
......@@ -54,6 +54,8 @@ function CMathBase(bInside)
Use : false
};
this.NearPosArray = [];
return this;
}
CMathBase.prototype =
......@@ -616,7 +618,10 @@ CMathBase.prototype.Recalculate_Reset = function(StartRange, StartLine)
CMathBase.prototype.Fill_LogicalContent = function(nCount)
{
for (var nIndex = 0; nIndex < nCount; nIndex++)
{
this.Content[nIndex] = new CMathContent();
this.Content[nIndex].ParentElement = this;
}
};
CMathBase.prototype.Copy = function()
{
......@@ -674,6 +679,7 @@ CMathBase.prototype.Read_FromBinary2 = function( Reader )
for (var nIndex = 0; nIndex < nCount; nIndex++)
{
this.Content[nIndex] = g_oTableId.Get_ById(Reader.GetString2());
this.Content[nIndex].ParentElement = this;
}
this.Pr.Read_FromBinary(Reader);
......@@ -837,15 +843,27 @@ CMathBase.prototype.Is_InnerSelection = function()
return false;
};
CMathBase.prototype.Select_ToRoot = function()
CMathBase.prototype.Select_WholeElement = function()
{
if (null !== this.Parent)
this.Parent.Select_ToRoot();
this.Parent.Select_Element(this, true);
};
CMathBase.prototype.Select_WholeElement = function()
CMathBase.prototype.Select_MathContent = function(MathContent)
{
if (null !== this.Parent)
this.Parent.Select_Element(this);
for (var nPos = 0, nCount = this.Content.length; nPos < nCount; nPos++)
{
if (this.Content[nPos] === MathContent)
{
if (null !== this.Parent)
{
this.Selection.Use = true;
this.Selection.StartPos = nPos;
this.Selection.EndPos = nPos;
this.Parent.Select_Element(this, false);
}
break;
}
}
};
CMathBase.prototype.Set_SelectionContentPos = ParaHyperlink.prototype.Set_SelectionContentPos;
CMathBase.prototype.Get_LeftPos = ParaHyperlink.prototype.Get_LeftPos;
......@@ -854,6 +872,7 @@ CMathBase.prototype.Get_WordStartPos = ParaHyperlink.prototype.Get_
CMathBase.prototype.Get_WordEndPos = ParaHyperlink.prototype.Get_WordEndPos;
CMathBase.prototype.Selection_Remove = ParaHyperlink.prototype.Selection_Remove;
CMathBase.prototype.Select_All = ParaHyperlink.prototype.Select_All;
CMathBase.prototype.Check_NearestPos = ParaHyperlink.prototype.Check_NearestPos;
CMathBase.prototype.Selection_CheckParaContentPos = function(ContentPos, Depth, bStart, bEnd)
{
if (true !== this.Selection.Use)
......
......@@ -688,6 +688,7 @@ function CMathContent()
};
this.NearPosArray = [];
this.ParentElement = null;
this.size = new CMathSize();
......@@ -1291,11 +1292,14 @@ CMathContent.prototype =
this.Add_ToContent(0, new ParaRun(null, true));
}
if (this.content.length == 1)
for (var nPos = 0, nCount = this.content.length; nPos < nCount; nPos++)
{
if(para_Math_Run === this.content[0].Type)
this.content[0].Math_Correct_Content();
if(para_Math_Run === this.content[nPos].Type)
this.content[nPos].Math_Correct_Content();
}
if (this.content.length == 1)
{
if(this.content[0].Is_Empty())
this.content[0].fillPlaceholders();
}
......@@ -1591,6 +1595,18 @@ CMathContent.prototype =
this.private_CorrectSelectionPos();
this.private_CorrectCurPos();
}
// Обновляем позиции в NearestPos
var NearPosLen = this.NearPosArray.length;
for ( var Index = 0; Index < NearPosLen; Index++ )
{
var HyperNearPos = this.NearPosArray[Index];
var ContentPos = HyperNearPos.NearPos.ContentPos;
var Depth = HyperNearPos.Depth;
if (ContentPos.Data[Depth] >= Pos)
ContentPos.Data[Depth]++;
}
},
private_CorrectSelectionPos : function()
......@@ -1621,35 +1637,55 @@ CMathContent.prototype =
var DeletedItems = this.content.splice(Pos, Count);
History.Add( this, { Type : historyitem_Math_RemoveItem, Pos : Pos, EndPos : Pos + Count - 1, Items : DeletedItems } );
if(this.CurPos > Pos)
{
if(this.CurPos >= Pos + Count)
this.CurPos -= Count;
else
this.CurPos = Pos;
// Обновим текущую позицию
if (this.CurPos > Pos + Count)
this.CurPos -= Count;
else if (this.CurPos > Pos )
this.CurPos = Pos;
this.private_CorrectCurPos();
}
this.private_CorrectCurPos();
if ( true === this.Selection.Use )
// Обновим начало и конец селекта
if (true === this.Selection.Use)
{
if(this.Selection.Start > Pos)
if (this.Selection.Start <= this.Selection.End)
{
if(this.Selection.Start >= Pos + Count)
if (this.Selection.Start > Pos + Count)
this.Selection.Start -= Count;
else
else if (this.Selection.Start > Pos)
this.Selection.Start = Pos;
}
if(this.Selection.End > Pos)
if (this.Selection.End >= Pos + Count)
this.Selection.End -= Count;
else if (this.Selection.End >= Pos)
this.Selection.End = Math.max(0, Pos - 1);
}
else
{
if(this.Selection.End >= Pos + Count)
if (this.Selection.Start >= Pos + Count)
this.Selection.Start -= Count;
else if (this.Selection.Start >= Pos)
this.Selection.Start = Math.max(0, Pos - 1);
if (this.Selection.End > Pos + Count)
this.Selection.End -= Count;
else
else if (this.Selection.End > Pos)
this.Selection.End = Pos;
}
}
this.private_CorrectSelectionPos();
// Обновляем позиции в NearestPos
var NearPosLen = this.NearPosArray.length;
for (var Index = 0; Index < NearPosLen; Index++)
{
var HyperNearPos = this.NearPosArray[Index];
var ContentPos = HyperNearPos.NearPos.ContentPos;
var Depth = HyperNearPos.Depth;
if (ContentPos.Data[Depth] > Pos + Count)
ContentPos.Data[Depth] -= Count;
else if (ContentPos.Data[Depth] > Pos)
ContentPos.Data[Depth] = Math.max(0 , Pos);
}
},
......@@ -1910,8 +1946,11 @@ CMathContent.prototype =
this.ParaMath.Refresh_RecalcData(); // Refresh_RecalcData сообщает родительскому классу, что у него произошли изменения, нужно пересчитать
},
Insert_MathContent : function(oMathContent, Pos)
Insert_MathContent : function(oMathContent, Pos, bSelect)
{
if (null === this.ParaMath || null === this.ParaMath.Paragraph)
bSelect = false;
if (undefined === Pos)
Pos = this.CurPos;
......@@ -1919,12 +1958,32 @@ CMathContent.prototype =
for (var nIndex = 0; nIndex < nCount; nIndex++)
{
this.Internal_Content_Add(Pos + nIndex, oMathContent.content[nIndex], false);
if (true === bSelect)
{
oMathContent.content[nIndex].Select_All();
}
}
if (null !== this.ParaMath)
this.ParaMath.SetNeedResize();
this.CurPos = Pos + 1 + nCount;
if (true === bSelect)
{
this.Selection.Use = true;
this.Selection.Start = Pos;
this.Selection.End = Pos + nCount - 1;
if (!this.bRoot)
this.ParentElement.Select_MathContent(this);
else
this.ParaMath.bSelectionUse = true;
this.ParaMath.Paragraph.Select_Math(this.ParaMath);
}
this.Correct_Content(true);
},
......@@ -3837,8 +3896,8 @@ CMathContent.prototype.Set_SelectionContentPos = function(StartContentPos, EndCo
if (OldStartPos > OldEndPos)
{
OldStartPos = this.Selection.EndPos;
OldEndPos = this.Selection.StartPos;
OldStartPos = this.Selection.End;
OldEndPos = this.Selection.Start;
}
var StartPos = 0;
......@@ -4279,24 +4338,23 @@ CMathContent.prototype.Selection_DrawRange = function(_CurLine, _CurRange, Selec
SelectionDraw.H = this.size.height;
}
};
CMathContent.prototype.Select_ToRoot = function()
{
this.Selection.Use = true;
this.Correct_Selection();
if(!this.bRoot)
this.Parent.Select_ToRoot();
};
CMathContent.prototype.Select_ElementByPos = function(nPos)
CMathContent.prototype.Select_ElementByPos = function(nPos, bWhole)
{
this.Selection.Use = true;
this.Selection.Start = nPos;
this.Selection.End = nPos;
this.content[this.Selection.Start].Select_All();
this.content[nPos].Select_All();
if (bWhole)
this.Correct_Selection();
if (!this.bRoot)
this.ParentElement.Select_MathContent(this);
else
this.ParaMath.bSelectionUse = true;
};
CMathContent.prototype.Select_Element = function(Element)
CMathContent.prototype.Select_Element = function(Element, bWhole)
{
var nPos = -1;
for (var nCurPos = 0, nCount = this.content.length; nCurPos < nCount; nCurPos++)
......@@ -4313,6 +4371,14 @@ CMathContent.prototype.Select_Element = function(Element)
this.Selection.Use = true;
this.Selection.Start = nPos;
this.Selection.End = nPos;
if (bWhole)
this.Correct_Selection();
if (!this.bRoot)
this.ParentElement.Select_MathContent(this);
else
this.ParaMath.bSelectionUse = true;
}
};
CMathContent.prototype.Correct_Selection = function()
......@@ -4350,13 +4416,11 @@ CMathContent.prototype.Correct_Selection = function()
this.content[this.Selection.End].Set_SelectionAtStartPos();
}
};
CMathContent.prototype.Create_FontMap = function(Map)
{
for (var nIndex = 0, nCount = this.content.length; nIndex < nCount; nIndex++)
this.content[nIndex].Create_FontMap(Map, this.Compiled_ArgSz); // ArgSize компилируется только тогда, когда выставлены все ссылки на родительские классы
};
CMathContent.prototype.Get_AllFontNames = function(AllFonts)
{
for (var nIndex = 0, nCount = this.content.length; nIndex < nCount; nIndex++)
......@@ -4372,4 +4436,16 @@ CMathContent.prototype.Selection_CheckParaContentPos = function(ContentPos, Dept
return this.content[CurPos].Selection_CheckParaContentPos(ContentPos, Depth + 1, bStart && this.Selection.End === CurPos, bEnd && CurPos === this.Selection.Start);
return false;
};
CMathContent.prototype.Check_NearestPos = function(ParaNearPos, Depth)
{
var HyperNearPos = new CParagraphElementNearPos();
HyperNearPos.NearPos = ParaNearPos.NearPos;
HyperNearPos.Depth = Depth;
this.NearPosArray.push(HyperNearPos);
ParaNearPos.Classes.push(this);
var CurPos = ParaNearPos.NearPos.ContentPos.Get(Depth);
this.content[CurPos].Check_NearestPos(ParaNearPos, Depth + 1);
};
\ No newline at end of file
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