Commit 1894d064 authored by Ilya Kirillov's avatar Ilya Kirillov

Improved performance of a paste function.

parent d7fb3e2b
...@@ -471,8 +471,7 @@ CHistory.prototype = ...@@ -471,8 +471,7 @@ CHistory.prototype =
{ {
// NumPr здесь не обнуляем // NumPr здесь не обнуляем
var NumPr = this.RecalculateData.NumPr; var NumPr = this.RecalculateData.NumPr;
this.RecalculateData = this.RecalculateData = {
{
Inline : { Inline : {
Pos : -1, Pos : -1,
PageNum : 0 PageNum : 0
...@@ -489,7 +488,10 @@ CHistory.prototype = ...@@ -489,7 +488,10 @@ CHistory.prototype =
NumPr : NumPr, NumPr : NumPr,
NotesEnd : false, NotesEnd : false,
NotesEndPage : 0, NotesEndPage : 0,
Update : true Update : true,
ChangedStyles : {},
ChangedNums : {},
AllParagraphs : null
}; };
}, },
...@@ -596,6 +598,33 @@ CHistory.prototype = ...@@ -596,6 +598,33 @@ CHistory.prototype =
} }
}, },
AddChangedStyleToRecalculateData : function(sId, oStyle)
{
if (!this.RecalculateData.ChangedStyles)
this.RecalculateData.ChangedStyles = {};
if (this.RecalculateData.ChangedStyles[sId] === oStyle)
return false;
this.RecalculateData.ChangedStyles[sId] = oStyle;
return true;
},
AddChangedNumberingToRecalculateData : function(NumId, Lvl, oNum)
{
if (!this.RecalculateData.ChangedNums)
this.RecalculateData.ChangedNums = {};
if (!this.RecalculateData.ChangedNums[NumId])
this.RecalculateData.ChangedNums[NumId] = {};
if (this.RecalculateData.ChangedNums[NumId][Lvl] === oNum)
return false;
this.RecalculateData.ChangedNums[NumId][Lvl] = oNum;
return true;
},
Add_RecalcNumPr : function(NumPr) Add_RecalcNumPr : function(NumPr)
{ {
if (undefined !== NumPr && null !== NumPr && undefined !== NumPr.NumId) if (undefined !== NumPr && null !== NumPr && undefined !== NumPr.NumId)
...@@ -1119,6 +1148,52 @@ CHistory.prototype.private_GetItemsCountInContentChange = function(Class, Data) ...@@ -1119,6 +1148,52 @@ CHistory.prototype.private_GetItemsCountInContentChange = function(Class, Data)
return 1; return 1;
}; };
CHistory.prototype.GetAllParagraphsForRecalcData = function(Props)
{
if (!this.RecalculateData.AllParagraphs)
{
if (this.Document)
this.RecalculateData.AllParagraphs = this.Document.Get_AllParagraphs({All : true});
else
this.RecalculateData.AllParagraphs = [];
}
var arrParagraphs = [];
if (!Props || true === Props.All)
{
return this.RecalculateData.AllParagraphs;
}
else if (true === Props.Style)
{
var arrStylesId = Props.StylesId;
for (var nParaIndex = 0, nParasCount = this.RecalculateData.AllParagraphs.length; nParaIndex < nParasCount; ++nParaIndex)
{
var oPara = this.RecalculateData.AllParagraphs[nParaIndex];
for (var nStyleIndex = 0, nStylesCount = arrStylesId.length; nStyleIndex < nStylesCount; ++nStyleIndex)
{
if (oPara.Pr.PStyle === arrStylesId[nStyleIndex])
{
arrParagraphs.push(oPara);
break;
}
}
}
}
else if (true === Props.Numbering)
{
for (var nParaIndex = 0, nParasCount = this.RecalculateData.AllParagraphs.length; nParaIndex < nParasCount; ++nParaIndex)
{
var oPara = this.RecalculateData.AllParagraphs[nParaIndex];
var NumPr = Props.NumPr;
var _NumPr = oPara.Numbering_Get();
if (undefined != _NumPr && _NumPr.NumId === NumPr.NumId && (_NumPr.Lvl === NumPr.Lvl || undefined === NumPr.Lvl))
arrParagraphs.push(oPara);
}
}
return arrParagraphs;
};
function CRC32() function CRC32()
{ {
......
...@@ -1605,12 +1605,18 @@ CAbstractNum.prototype = ...@@ -1605,12 +1605,18 @@ CAbstractNum.prototype =
Refresh_RecalcData : function(Data) Refresh_RecalcData : function(Data)
{ {
var oHistory = History;
if (!oHistory)
return;
if (!oHistory.AddChangedNumberingToRecalculateData(this.Get_Id(), Data.Index, this))
return;
var NumPr = new CNumPr(); var NumPr = new CNumPr();
NumPr.NumId = this.Id; NumPr.NumId = this.Id;
NumPr.Lvl = Data.Index; NumPr.Lvl = Data.Index;
var LogicDocument = editor.WordControl.m_oLogicDocument; var AllParagraphs = oHistory.GetAllParagraphsForRecalcData({Numbering : true, NumPr : NumPr});
var AllParagraphs = LogicDocument.Get_AllParagraphsByNumbering( NumPr );
var Count = AllParagraphs.length; var Count = AllParagraphs.length;
for ( var Index = 0; Index < Count; Index++ ) for ( var Index = 0; Index < Count; Index++ )
......
...@@ -2828,7 +2828,13 @@ CStyle.prototype = ...@@ -2828,7 +2828,13 @@ CStyle.prototype =
Refresh_RecalcData2 : function() Refresh_RecalcData2 : function()
{ {
// TODO: Надо сделать механизм, чтобы данное действие не вызывалось много раз подряд, а только 1. var oHistory = History;
if (!oHistory)
return;
if (!oHistory.AddChangedStyleToRecalculateData(this.Get_Id(), this))
return;
var LogicDocument = editor.WordControl.m_oLogicDocument; var LogicDocument = editor.WordControl.m_oLogicDocument;
var Styles = LogicDocument.Get_Styles(); var Styles = LogicDocument.Get_Styles();
...@@ -2837,20 +2843,20 @@ CStyle.prototype = ...@@ -2837,20 +2843,20 @@ CStyle.prototype =
if (this.Id != Styles.Default.Paragraph) if (this.Id != Styles.Default.Paragraph)
{ {
var AllStylesId = Styles.private_GetAllBasedStylesId(this.Id); var AllStylesId = Styles.private_GetAllBasedStylesId(this.Id);
AllParagraphs = LogicDocument.Get_AllParagraphsByStyle(AllStylesId); AllParagraphs = oHistory.GetAllParagraphsForRecalcData({Style : true, StylesId : AllStylesId});
LogicDocument.Add_ChangedStyle(AllStylesId); LogicDocument.Add_ChangedStyle(AllStylesId);
} }
else else
{ {
AllParagraphs = LogicDocument.Get_AllParagraphs({All : true}); AllParagraphs = oHistory.GetAllParagraphsForRecalcData({All : true});
LogicDocument.Add_ChangedStyle([this.Id]); LogicDocument.Add_ChangedStyle([this.Id]);
} }
var Count = AllParagraphs.length; var Count = AllParagraphs.length;
for ( var Index = 0; Index < Count; Index++ ) for (var Index = 0; Index < Count; Index++)
{ {
var Para = AllParagraphs[Index]; var Para = AllParagraphs[Index];
Para.Refresh_RecalcData( { Type : AscDFH.historyitem_Paragraph_PStyle } ); Para.Refresh_RecalcData({Type : AscDFH.historyitem_Paragraph_PStyle});
} }
}, },
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
......
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