Commit 3bd9105c authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander.Trofimov

Переделано Undo/Redo в формулах.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@58644 954022d7-b5bf-4e40-9824-e11837661b57
parent a3c27448
...@@ -249,7 +249,7 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText) ...@@ -249,7 +249,7 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText)
var oParent = oContent.GetParent(); var oParent = oContent.GetParent();
oParent.SetSelectAll(); oParent.SetSelectAll();
oParent.SelectToParent(); oParent.SelectToParent(true);
this.bSelectionUse = true; this.bSelectionUse = true;
return true; return true;
...@@ -276,7 +276,7 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText) ...@@ -276,7 +276,7 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText)
else else
{ {
oContent.SelectElement(nStartPos + 1); oContent.SelectElement(nStartPos + 1);
oContent.SelectToParent(); oContent.SelectToParent(true);
this.bSelectionUse = true; this.bSelectionUse = true;
} }
} }
...@@ -301,7 +301,7 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText) ...@@ -301,7 +301,7 @@ ParaMath.prototype.Remove = function(Direction, bOnAddText)
else else
{ {
oContent.SelectElement(nStartPos - 1); oContent.SelectElement(nStartPos - 1);
oContent.SelectToParent(); oContent.SelectToParent(true);
this.bSelectionUse = true; this.bSelectionUse = true;
} }
} }
......
...@@ -10006,7 +10006,7 @@ Paragraph.prototype = ...@@ -10006,7 +10006,7 @@ Paragraph.prototype =
X : this.CurPos.X, X : this.CurPos.X,
Y : this.CurPos.Y, Y : this.CurPos.Y,
Line : this.CurPos.Line, Line : this.CurPos.Line,
ContentPos : ( true === this.Selection.Use ? this.Get_ParaContentPos( true, false ) : this.Get_ParaContentPos( false, false ) ), ContentPos : this.Get_ParaContentPos(false, false),
RealX : this.CurPos.RealX, RealX : this.CurPos.RealX,
RealY : this.CurPos.RealY, RealY : this.CurPos.RealY,
PagesPos : this.CurPos.PagesPos PagesPos : this.CurPos.PagesPos
......
...@@ -4343,6 +4343,16 @@ ParaRun.prototype.Set_SelectionContentPos = function(StartContentPos, EndContent ...@@ -4343,6 +4343,16 @@ ParaRun.prototype.Set_SelectionContentPos = function(StartContentPos, EndContent
Selection.Use = true; Selection.Use = true;
}; };
ParaRun.prototype.Set_SelectionAtEndPos = function()
{
this.Set_SelectionContentPos(null, null, 0, -1, -1);
};
ParaRun.prototype.Set_SelectionAtStartPos = function()
{
this.Set_SelectionContentPos(null, null, 0, 1, 1);
};
ParaRun.prototype.Selection_IsUse = function() ParaRun.prototype.Selection_IsUse = function()
{ {
return this.State.Selection.Use; return this.State.Selection.Use;
......
...@@ -1150,10 +1150,10 @@ CMathBase.prototype = ...@@ -1150,10 +1150,10 @@ CMathBase.prototype =
this.bSelectionUse = true; this.bSelectionUse = true;
}, },
SelectToParent: function() SelectToParent: function(bCorrect)
{ {
this.bSelectionUse = true; this.bSelectionUse = true;
this.Parent.SelectToParent(); this.Parent.SelectToParent(bCorrect);
}, },
Check_NearestPos: function(ParaNearPos, Depth) Check_NearestPos: function(ParaNearPos, Depth)
{ {
......
...@@ -3902,7 +3902,7 @@ CMathContent.prototype = ...@@ -3902,7 +3902,7 @@ CMathContent.prototype =
{ {
History.Create_NewPoint(); History.Create_NewPoint();
var Items = this.content.slice(Pos, EndPos); var Items = this.content.slice(Pos, EndPos);
History.Add(this, {Type: historyitem_Math_AddItem, Items: Items, Pos: Pos, PosEnd: EndPos}); History.Add(this, {Type: historyitem_Math_AddItem, Items: Items, Pos: Pos, PosEnd: EndPos, EndPos: EndPos});
} }
var items = this.content.slice(Pos, EndPos); var items = this.content.slice(Pos, EndPos);
...@@ -4454,7 +4454,6 @@ CMathContent.prototype = ...@@ -4454,7 +4454,6 @@ CMathContent.prototype =
} }
this.Selection.Use = true; this.Selection.Use = true;
}, },
GetSelectContent: function() GetSelectContent: function()
{ {
...@@ -4517,6 +4516,42 @@ CMathContent.prototype = ...@@ -4517,6 +4516,42 @@ CMathContent.prototype =
this.content[this.Selection.Start].SetSelectAll(); this.content[this.Selection.Start].SetSelectAll();
}, },
Correct_Selection : function()
{
if (true !== this.Selection.Use)
return;
// Здесь мы делаем так, чтобы селект всегда начинался и заканчивался в ране.
// Предполагается, что контент скорректирован верно до выполнения данной функции.
var nContentLen = this.content.length;
var nStartPos = Math.max(0, Math.min(this.Selection.Start, nContentLen - 1));
var nEndPos = Math.max(0, Math.min(this.Selection.End, nContentLen - 1));
if (nStartPos > nEndPos)
{
var nTemp = nStartPos;
nStartPos = nEndPos;
nEndPos = nTemp;
}
var oStartElement = this.content[nStartPos];
if (para_Math_Run !== oStartElement.Type)
{
// Предыдущий элемент должен быть раном
this.Selection.Start = nStartPos - 1;
this.content[this.Selection.Start].Set_SelectionAtEndPos();
}
var oEndElement = this.content[nEndPos];
if (para_Math_Run !== oEndElement.Type)
{
// Следующий элемент должен быть раном
this.Selection.End = nEndPos + 1;
this.content[this.Selection.End].Set_SelectionAtStartPos();
}
},
Is_SelectedAll: function(Props) Is_SelectedAll: function(Props)
{ {
var bFirst = false, bEnd = false; var bFirst = false, bEnd = false;
...@@ -4548,12 +4583,15 @@ CMathContent.prototype = ...@@ -4548,12 +4583,15 @@ CMathContent.prototype =
return result; return result;
}, },
SelectToParent : function() SelectToParent : function(bCorrect)
{ {
this.Selection.Use = true; this.Selection.Use = true;
if (true === bCorrect)
this.Correct_Selection();
if(!this.bRoot) if(!this.bRoot)
this.Parent.SelectToParent(); this.Parent.SelectToParent(false);
}, },
Selection_DrawRange: function(_CurLine, _CurRange, SelectionDraw) Selection_DrawRange: function(_CurLine, _CurRange, SelectionDraw)
...@@ -5279,7 +5317,7 @@ CMathContent.prototype = ...@@ -5279,7 +5317,7 @@ CMathContent.prototype =
}, },
Internal_Content_Add : function(Pos, Item) Internal_Content_Add : function(Pos, Item)
{ {
History.Add( this, { Type : historyitem_Math_AddItem, Pos : Pos, EndPos : Pos + 1, Items : [ Item ] } ); History.Add( this, { Type : historyitem_Math_AddItem, Pos : Pos, EndPos : Pos, Items : [ Item ] } );
this.content.splice( Pos, 0, Item ); this.content.splice( Pos, 0, Item );
if ( this.CurPos >= Pos ) if ( this.CurPos >= Pos )
...@@ -5301,7 +5339,7 @@ CMathContent.prototype = ...@@ -5301,7 +5339,7 @@ CMathContent.prototype =
Remove_FromContent : function(Pos, Count) Remove_FromContent : function(Pos, Count)
{ {
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, 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)
{ {
...@@ -5660,33 +5698,17 @@ CMathContent.prototype = ...@@ -5660,33 +5698,17 @@ CMathContent.prototype =
{ {
case historyitem_Math_AddItem: case historyitem_Math_AddItem:
{ {
var Pos = Data.Pos, this.content.splice(Data.Pos, Data.EndPos - Data.Pos + 1);
PosEnd = Data.PosEnd;
var Content_start = this.content.slice(0, Pos);
var Content_end = this.content.slice(PosEnd);
this.content = Content_start.concat(Content_end);
this.CurPos = Pos - 1;
this.setPlaceholderAfterRemove(); // выставляем placeholder после удаления всех остальных элементов
break; break;
} }
case historyitem_Math_RemoveItem: case historyitem_Math_RemoveItem:
{ {
var Pos = Data.Pos; var Pos = Data.Pos;
if( this.IsPlaceholder() ) //удаляем тагет var Array_start = this.content.slice(0, Pos);
{ var Array_end = this.content.slice(Pos);
var empty = this.content[0]; //CEmpty
this.content.length = 0;
this.content.push( empty );
}
var Content_start = this.content.slice(0, Pos); this.content = Array_start.concat(Data.Items, Array_end);
var Content_end = this.content.slice(Pos);
this.content = Content_start.concat(Data.Items, Content_end);
break; break;
} }
} }
...@@ -5701,39 +5723,16 @@ CMathContent.prototype = ...@@ -5701,39 +5723,16 @@ CMathContent.prototype =
{ {
var Pos = Data.Pos; var Pos = Data.Pos;
if( this.IsPlaceholder() ) //удаляем тагет var Array_start = this.content.slice(0, Pos);
{ var Array_end = this.content.slice(Pos);
var empty = this.content[0]; //CEmpty
this.content.length = 0;
this.content.push( empty );
}
var Content_start = this.content.slice(0, Pos);
var Content_end = this.content.slice(Pos);
this.setStartPos_Selection(Pos); this.content = Array_start.concat(Data.Items, Array_end);
//this.selection.active = false;
this.content = Content_start.concat(Data.Items, Content_end);
break; break;
} }
case historyitem_Math_RemoveItem: case historyitem_Math_RemoveItem:
{ {
this.content.splice(Data.Pos, Data.EndPos - Data.Pos + 1);
var Pos = Data.Pos,
PosEnd = Pos + Data.Items.length;
var Content_start = this.content.slice(0, Pos);
var Content_end = this.content.slice(PosEnd);
this.setStartPos_Selection(Pos);
//this.selection.active = false;
this.content = Content_start.concat(Content_end);
this.CurPos = Pos - 1;
this.setPlaceholderAfterRemove(); // выставляем placeholder после удаления всех остальных элементов
break; break;
} }
} }
}, },
......
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