From 9d9a0bc017b8655f40f70833d06e411ec789cb43 Mon Sep 17 00:00:00 2001
From: "Ilya.Kirillov" <Ilya.Kirillov@OnlyOffice.com>
Date: Fri, 20 Jun 2014 10:22:28 +0000
Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?=
 =?UTF-8?q?=D0=B5=D0=BD=20=D0=B1=D0=B0=D0=B3=20=D0=BF=D1=80=D0=B8=20=D1=83?=
 =?UTF-8?q?=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=B2=20=D0=B3?=
 =?UTF-8?q?=D0=B8=D0=BF=D0=B5=D1=80=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B0?=
 =?UTF-8?q?=D1=85.=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?=
 =?UTF-8?q?=D0=BD=20=D0=B1=D0=B0=D0=B3=20=D1=81=20drag-n-drop=20=D0=B0?=
 =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=84=D0=B8=D0=B3=D1=83=D1=80=20=D0=B2=20?=
 =?UTF-8?q?=D0=B0=D0=B2=D1=82=D0=BE=D1=84=D0=B8=D0=B3=D1=83=D1=80=D1=8B=20?=
 =?UTF-8?q?(=D0=B1=D0=B0=D0=B3=2024181).=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?=
 =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B1=D0=B0=D0=B3=20=D1=81=20=D1=83?=
 =?UTF-8?q?=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=B2=20?=
 =?UTF-8?q?=D0=B0=D0=B2=D1=82=D0=BE=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0?=
 =?UTF-8?q?=D1=85=20=D0=B2=20=D0=BA=D0=BE=D0=BB=D0=BE=D0=BD=D1=82=D0=B8?=
 =?UTF-8?q?=D1=82=D1=83=D0=BB=D0=B5=20(=D0=B1=D0=B0=D0=B3=2024400).?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56821 954022d7-b5bf-4e40-9824-e11837661b57
---
 Word/Editor/Document.js  | 21 ++++++++++--
 Word/Editor/Hyperlink.js | 10 +++---
 Word/Editor/Paragraph.js | 69 +++++++++++++++++++++++++++-------------
 3 files changed, 71 insertions(+), 29 deletions(-)

diff --git a/Word/Editor/Document.js b/Word/Editor/Document.js
index 53bf03aae..b06f1ffee 100644
--- a/Word/Editor/Document.js
+++ b/Word/Editor/Document.js
@@ -75,6 +75,8 @@ function CSelectedElement(Element, SelectedAll)
 function CSelectedContent()
 {
     this.Elements = [];
+    
+    this.HaveShape = false;
 }
 
 CSelectedContent.prototype =
@@ -87,6 +89,11 @@ CSelectedContent.prototype =
     Add : function(Element)
     {
         this.Elements.push( Element );
+    },
+    
+    Set_Shape : function(Value)
+    {
+       this.HaveShape = Value; 
     }
 };
 
@@ -2990,8 +2997,11 @@ CDocument.prototype =
         {
             var Res = this.HdrFtr.Remove(Count, bOnlyText, bRemoveOnlySelection, bOnTextAdd);
 
-            this.Selection_Remove();
-            this.Selection.Use = false;
+            if ( null !== this.HdrFtr.CurHdtr && docpostype_DrawingObjects !== this.HdrFtr.CurHdrFtr.Content.CurPos.Type )
+            {
+                this.Selection_Remove();
+                this.Selection.Use = false;
+            }
 
             this.Document_UpdateInterfaceState();
             this.Document_UpdateRulersState();
@@ -8274,6 +8284,13 @@ CDocument.prototype =
             this.Get_SelectedContent( DocContent );
 
             var Para = NearPos.Paragraph;
+            
+            // Автофигуры не вставляем в другие автофигуры
+            if ( true === Para.Parent.Is_DrawingShape() && true === DocContent.HaveShape )
+            {
+                History.Remove_LastPoint();
+                return;
+            }
 
             // Заполним массив для проверки лока
             var ArrayForCheck = [];
diff --git a/Word/Editor/Hyperlink.js b/Word/Editor/Hyperlink.js
index 36d4f3fb1..ff37a6c8a 100644
--- a/Word/Editor/Hyperlink.js
+++ b/Word/Editor/Hyperlink.js
@@ -439,7 +439,7 @@ ParaHyperlink.prototype =
 
                 if ( StartPos !== this.Content.length - 1 && true === this.Content[StartPos].Is_Empty() )
                 {
-                    this.Remove_FromContent( StartPos, true );
+                    this.Remove_FromContent( StartPos, 1, true );
                 }
             }
             else
@@ -448,18 +448,18 @@ ParaHyperlink.prototype =
 
                 if ( EndPos !== this.Content.length - 1 && true === this.Content[EndPos].Is_Empty() )
                 {
-                    this.Remove_FromContent( EndPos, true );
+                    this.Remove_FromContent( EndPos, 1, true );
                 }
 
                 for ( var CurPos = EndPos - 1; CurPos > StartPos; CurPos-- )
                 {
-                    this.Remove_FromContent( EndPos, true );
+                    this.Remove_FromContent( EndPos, 1, true );
                 }
 
                 this.Content[StartPos].Remove(Direction, bOnAddText);
 
                 if ( true === this.Content[StartPos].Is_Empty() )
-                    this.Remove_FromContent( StartPos, true );
+                    this.Remove_FromContent( StartPos, 1, true );
             }
 
             this.Selection_Remove();
@@ -497,7 +497,7 @@ ParaHyperlink.prototype =
                 else
                 {
                     if ( ContentPos !== this.Content.length - 1 && true === this.Content[ContentPos].Is_Empty() )
-                        this.Remove_FromContent( ContentPos, true );
+                        this.Remove_FromContent( ContentPos, 1, true );
 
                     this.State.ContentPos = ContentPos;
                 }
diff --git a/Word/Editor/Paragraph.js b/Word/Editor/Paragraph.js
index f970ff60f..238c4e5dd 100644
--- a/Word/Editor/Paragraph.js
+++ b/Word/Editor/Paragraph.js
@@ -4767,6 +4767,7 @@ Paragraph.prototype =
             else
             {
                 var SearchPos = new CParagraphSearchPos();
+                SearchPos.ForSelection = true;
 
                 if ( true === Word )
                     this.Get_WordStartPos( SearchPos, EndSelectionPos );
@@ -4866,6 +4867,7 @@ Paragraph.prototype =
             else
             {
                 var SearchPos = new CParagraphSearchPos();
+                SearchPos.ForSelection = true;
 
                 if ( true === Word )
                     this.Get_WordEndPos( SearchPos, EndSelectionPos, true );
@@ -7069,38 +7071,59 @@ Paragraph.prototype =
             EndPos   = this.Selection.StartPos;
         }
 
+        var Para = null;
         if ( true === this.Selection_IsFromStart() && true === this.Selection_CheckParaEnd() )
         {
-            DocContent.Add( new CSelectedElement( this.Copy(this.Parent), true ) );
-            return;
+            Para = this.Copy(this.Parent);
+            DocContent.Add( new CSelectedElement( Para, true ) );
         }
+        else
+        {
+            Para = new Paragraph(this.DrawingDocument, this.Parent, 0, 0, 0, 0, 0);
 
-        var Para = new Paragraph(this.DrawingDocument, this.Parent, 0, 0, 0, 0, 0);
+            // Копируем настройки
+            Para.Set_Pr(this.Pr.Copy());
+            Para.TextPr.Set_Value( this.TextPr.Value.Copy() );
 
-        // Копируем настройки
-        Para.Set_Pr(this.Pr.Copy());
-        Para.TextPr.Set_Value( this.TextPr.Value.Copy() );
+            // Копируем содержимое параграфа
+            for ( var Pos = StartPos; Pos <= EndPos; Pos++ )
+            {
+                var Item = this.Content[Pos];
+
+                if ( StartPos === Pos || EndPos === Pos )
+                    Para.Internal_Content_Add( Pos - StartPos, Item.Copy(true), false );
+                else
+                    Para.Internal_Content_Add( Pos - StartPos, Item.Copy(false), false );
+            }
+
+            // Добавляем секцию в конце
+            if ( undefined !== this.SectPr )
+            {
+                var SectPr = new CSectionPr(this.SectPr.LogicDocument);
+                SectPr.Copy(this.SectPr);
+                Para.Set_SectionPr(SectPr);
+            }
+            DocContent.Add( new CSelectedElement( Para, false ) );
+        }
         
-        // Копируем содержимое параграфа
-        for ( var Pos = StartPos; Pos <= EndPos; Pos++ )
+        if ( null !== Para && false === DocContent.HaveShape )
         {
-            var Item = this.Content[Pos];
+            // Проверим есть ли у нас автофигуры в параграфе
+            var DrawingObjects = Para.Get_AllDrawingObjects();
 
-            if ( StartPos === Pos || EndPos === Pos )
-                Para.Internal_Content_Add( Pos - StartPos, Item.Copy(true), false );
-            else
-                Para.Internal_Content_Add( Pos - StartPos, Item.Copy(false), false );
-        }
+            var Count = DrawingObjects.length;
+            for ( var Index = 0; Index < Count; Index++ )
+            {
+                var DrawingObj = DrawingObjects[Index];
+                var ShapeType = DrawingObj.GraphicObj.getObjectType();
 
-        // Добавляем секцию в конце
-        if ( undefined !== this.SectPr )
-        {
-            var SectPr = new CSectionPr(this.SectPr.LogicDocument);
-            SectPr.Copy(this.SectPr);
-            Para.Set_SectionPr(SectPr);
+                if ( historyitem_type_Shape === ShapeType || historyitem_type_GroupShape === ShapeType )
+                {
+                    DocContent.Set_Shape( true );
+                    break;
+                }
+            }
         }
-
-        DocContent.Add( new CSelectedElement( Para, false ) );
     },
 
     Get_Paragraph_TextPr : function()
@@ -13791,6 +13814,8 @@ function CParagraphSearchPos()
     this.Punctuation = false;
     this.First       = true;
     this.UpdatePos   = false;
+    
+    this.ForSelection = false;
 }
 
 function CParagraphSearchPosXY()
-- 
2.30.9