Commit 5c08aaf4 authored by Ilya Kirillov's avatar Ilya Kirillov

Implemented functions for removing content control wrapping.

parent aed39e23
...@@ -15229,16 +15229,37 @@ CDocument.prototype.GetAllContentControls = function() ...@@ -15229,16 +15229,37 @@ CDocument.prototype.GetAllContentControls = function()
}; };
CDocument.prototype.RemoveContentControl = function(Id) CDocument.prototype.RemoveContentControl = function(Id)
{ {
var oBlockLevelSdt = this.TableId.Get_ById(Id); var oContentControl = this.TableId.Get_ById(Id);
if (oBlockLevelSdt && oBlockLevelSdt.Parent) if (!oContentControl)
return;
if (AscCommonWord.sdttype_BlockLevel === oContentControl.GetContentControlType() && oContentControl.Parent)
{ {
this.RemoveSelection(); this.RemoveSelection();
var oDocContent = oBlockLevelSdt.Parent; var oDocContent = oContentControl.Parent;
oDocContent.Update_ContentIndexing(); oDocContent.Update_ContentIndexing();
var nIndex = oBlockLevelSdt.GetIndex(); var nIndex = oContentControl.GetIndex();
oDocContent.Remove_FromContent(nIndex, 1); oDocContent.Remove_FromContent(nIndex, 1);
oDocContent.MoveCursorToStartPos(); oDocContent.MoveCursorToStartPos();
} }
else if (AscCommonWord.sdttype_InlineLevel === oContentControl.GetContentControlType())
{
this.SelectContentControl(Id);
this.RemoveBeforePaste();
}
};
CDocument.prototype.RemoveContentControlWrapper = function(Id)
{
var oContentControl = this.TableId.Get_ById(Id);
if (!oContentControl)
return;
this.History.Create_NewPoint();
oContentControl.RemoveContentControlWrapper();
this.Recalculate();
this.Document_UpdateInterfaceState();
this.Document_UpdateSelectionState();
}; };
CDocument.prototype.GetContentControl = function(Id) CDocument.prototype.GetContentControl = function(Id)
{ {
......
...@@ -626,8 +626,8 @@ CParagraphContentWithParagraphLikeContent.prototype.Remove_FromContent = functio ...@@ -626,8 +626,8 @@ CParagraphContentWithParagraphLikeContent.prototype.Remove_FromContent = functio
this.State.Selection.EndPos = Pos; this.State.Selection.EndPos = Pos;
} }
this.Selection.StartPos = Math.min(this.Content.length - 1, Math.max(0, this.Selection.StartPos)); this.Selection.StartPos = Math.max(0, Math.min(this.Content.length - 1, this.Selection.StartPos));
this.Selection.EndPos = Math.min(this.Content.length - 1, Math.max(0, this.Selection.EndPos)); this.Selection.EndPos = Math.max(0, Math.min(this.Content.length - 1, this.Selection.EndPos));
} }
// Также передвинем всем метки переносов страниц и строк // Также передвинем всем метки переносов страниц и строк
...@@ -1185,9 +1185,6 @@ CParagraphContentWithParagraphLikeContent.prototype.Get_ContentLength = function ...@@ -1185,9 +1185,6 @@ CParagraphContentWithParagraphLikeContent.prototype.Get_ContentLength = function
}; };
CParagraphContentWithParagraphLikeContent.prototype.Get_Parent = function() CParagraphContentWithParagraphLikeContent.prototype.Get_Parent = function()
{ {
if (this.Parent)
return this.Parent;
if (!this.Paragraph) if (!this.Paragraph)
return null; return null;
...@@ -1969,7 +1966,7 @@ CParagraphContentWithParagraphLikeContent.prototype.Set_SelectionContentPos = fu ...@@ -1969,7 +1966,7 @@ CParagraphContentWithParagraphLikeContent.prototype.Set_SelectionContentPos = fu
// Удалим отметки о старом селекте // Удалим отметки о старом селекте
if ( OldStartPos < StartPos && OldStartPos < EndPos ) if ( OldStartPos < StartPos && OldStartPos < EndPos )
{ {
var TempBegin = OldStartPos; var TempBegin = Math.max(0, OldStartPos);
var TempEnd = Math.min(this.Content.length - 1, Math.min(StartPos, EndPos) - 1); var TempEnd = Math.min(this.Content.length - 1, Math.min(StartPos, EndPos) - 1);
for (var CurPos = TempBegin; CurPos <= TempEnd; ++CurPos) for (var CurPos = TempBegin; CurPos <= TempEnd; ++CurPos)
{ {
...@@ -1979,7 +1976,7 @@ CParagraphContentWithParagraphLikeContent.prototype.Set_SelectionContentPos = fu ...@@ -1979,7 +1976,7 @@ CParagraphContentWithParagraphLikeContent.prototype.Set_SelectionContentPos = fu
if ( OldEndPos > StartPos && OldEndPos > EndPos ) if ( OldEndPos > StartPos && OldEndPos > EndPos )
{ {
var TempBegin = Math.max(StartPos, EndPos) + 1; var TempBegin = Math.max(0, Math.max(StartPos, EndPos) + 1);
var TempEnd = Math.min(OldEndPos, this.Content.length - 1); var TempEnd = Math.min(OldEndPos, this.Content.length - 1);
for (var CurPos = TempBegin; CurPos <= TempEnd; ++CurPos) for (var CurPos = TempBegin; CurPos <= TempEnd; ++CurPos)
{ {
......
...@@ -868,6 +868,44 @@ CBlockLevelSdt.prototype.SelectContentControl = function() ...@@ -868,6 +868,44 @@ CBlockLevelSdt.prototype.SelectContentControl = function()
this.SelectAll(1); this.SelectAll(1);
this.Set_CurrentElement(false, 0, this.Content); this.Set_CurrentElement(false, 0, this.Content);
}; };
CBlockLevelSdt.prototype.RemoveContentControlWrapper = function()
{
if (!this.Parent)
return;
this.Parent.Update_ContentIndexing();
var nElementPos = this.GetIndex();
if (this.Parent.Content[nElementPos] !== this)
return;
var nParentCurPos = this.Parent.CurPos.ContentPos;
var nParentSelectionStartPos = this.Parent.Selection.StartPos;
var nParentSelectionEndPos = this.Parent.Selection.EndPos;
this.Parent.Remove_FromContent(nElementPos, 1);
for (var nIndex = 0, nCount = this.Content.Content.length; nIndex < nCount; ++nIndex)
{
this.Parent.Add_ToContent(nElementPos + nIndex, this.Content.Content[nIndex]);
}
if (nParentCurPos === nElementPos)
this.Parent.CurPos.ContentPos = nParentCurPos + this.Content.CurPos.ContentPos;
else if (nParentCurPos > nElementPos)
this.Parent.CurPos.ContentPos = nParentCurPos + nCount - 1;
if (nParentSelectionStartPos === nElementPos)
this.Parent.Selection.StartPos = nParentSelectionStartPos + this.Content.Selection.StartPos;
else if (nParentSelectionStartPos > nElementPos)
this.Parent.Selection.StartPos = nParentSelectionStartPos + nCount - 1;
if (nParentSelectionEndPos === nElementPos)
this.Parent.Selection.EndPos = nParentSelectionEndPos + this.Content.Selection.EndPos;
else if (nParentSelectionEndPos > nElementPos)
this.Parent.Selection.EndPos = nParentSelectionEndPos + nCount - 1;
this.Content.Remove_FromContent(0, this.Content.Content.length - 1);
};
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
CBlockLevelSdt.prototype.GetContentControlType = function() CBlockLevelSdt.prototype.GetContentControlType = function()
{ {
......
...@@ -252,6 +252,55 @@ CInlineLevelSdt.prototype.SelectContentControl = function() ...@@ -252,6 +252,55 @@ CInlineLevelSdt.prototype.SelectContentControl = function()
{ {
this.SelectThisElement(1); this.SelectThisElement(1);
}; };
CInlineLevelSdt.prototype.RemoveContentControlWrapper = function()
{
var oParent = this.Get_Parent();
if (!oParent)
return;
var nElementPos = this.Get_PosInParent(oParent);
if (-1 === nElementPos)
return;
var nParentCurPos = oParent instanceof Paragraph ? oParent.CurPos.ContentPos : oParent.State.ContentPos;
var nParentSelectionStartPos = oParent.Selection.StartPos;
var nParentSelectionEndPos = oParent.Selection.EndPos;
var nCount = this.Content.length;
oParent.Remove_FromContent(nElementPos, 1);
for (var nIndex = 0; nIndex < nCount; ++nIndex)
{
oParent.Add_ToContent(nElementPos + nIndex, this.Content[nIndex]);
}
if (nParentCurPos === nElementPos)
{
if (oParent instanceof Paragraph)
oParent.CurPos.ContentPos = nParentCurPos + this.State.ContentPos;
else
oParent.State.ContentPos = nParentCurPos + this.State.ContentPos;
}
else if (nParentCurPos > nElementPos)
{
if (oParent instanceof Paragraph)
oParent.CurPos.ContentPos = nParentCurPos + nCount - 1;
else
oParent.State.ContentPos = nParentCurPos + nCount - 1;
}
if (nParentSelectionStartPos === nElementPos)
oParent.Selection.StartPos = nParentSelectionStartPos + this.Selection.StartPos;
else if (nParentSelectionStartPos > nElementPos)
oParent.Selection.StartPos = nParentSelectionStartPos + nCount - 1;
if (nParentSelectionEndPos === nElementPos)
oParent.Selection.EndPos = nParentSelectionEndPos + this.Selection.EndPos;
else if (nParentSelectionEndPos > nElementPos)
oParent.Selection.EndPos = nParentSelectionEndPos + nCount - 1;
this.Remove_FromContent(0, this.Content.length);
};
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
// Выставление настроек // Выставление настроек
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
......
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