Commit 2409a300 authored by Ilya.Kirillov's avatar Ilya.Kirillov

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

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