From 609c5d798bb8ea8661ffbcc8e12865137efec364 Mon Sep 17 00:00:00 2001
From: "Ilya.Kirillov" <Ilya.Kirillov@OnlyOffice.com>
Date: Fri, 3 Oct 2014 13:04:22 +0000
Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?=
 =?UTF-8?q?=D0=BD=D1=8B=20=D0=BC=D0=B5=D1=85=D0=B0=D0=BD=D0=B8=D0=B7=D0=BC?=
 =?UTF-8?q?=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1?=
 =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B8=20=D0=B0=D0=B2=D1=82=D0=BE=D0=B7=D0=B0?=
 =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8B=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC?=
 =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=85=20=D0=B8=20=D0=BE=D0=B1=D1=80=D0=B0?=
 =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=BA=D0=B8=20=D0=BD=D0=B0=D0=B6=D0=B0=D1=82?=
 =?UTF-8?q?=D0=B8=D1=8F=20Enter=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D1=83?=
 =?UTF-8?q?=D0=BB=D0=B0=D1=85.=20=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5?=
 =?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE?=
 =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?=
 =?UTF-8?q?=D0=B8=D1=8F=20=D1=84=D0=BE=D1=80=D0=BC=D1=83=D0=BB=D1=8B=20?=
 =?UTF-8?q?=D1=81=20Inline=20=D0=BD=D0=B0=20=D0=BD=D0=B5=20Inline.?=
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@58654 954022d7-b5bf-4e40-9824-e11837661b57
---
 Word/Editor/Document.js              | 70 +++++++++++++++++++++-------
 Word/Editor/Math.js                  | 39 ++++++++++++++++
 Word/Editor/Paragraph.js             |  5 ++
 Word/Editor/Paragraph_Recalculate.js |  4 +-
 4 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/Word/Editor/Document.js b/Word/Editor/Document.js
index ae2808620..a0df9cd5e 100644
--- a/Word/Editor/Document.js
+++ b/Word/Editor/Document.js
@@ -664,6 +664,7 @@ function CSelectedElementsInfo()
     this.m_bMixedSelection = false; // Попадает ли в выделение одновременно несколько элементов
     this.m_nDrawing        = selected_None;
     this.m_pParagraph      = null;  // Параграф, в котором находится выделение
+    this.m_oMath           = null;  // Формула, в которой находится выделение
 
     this.Reset = function()
     {
@@ -678,11 +679,21 @@ function CSelectedElementsInfo()
         this.m_pParagraph = Para;
     };
 
+    this.Set_Math = function(Math)
+    {
+        this.m_oMath = Math;
+    };
+
     this.Get_Paragraph = function()
     {
         return this.m_pParagraph;
     };
 
+    this.Get_Math = function()
+    {
+        return this.m_oMath;
+    };
+
     this.Set_Table = function()
     {
         this.m_bTable = true;
@@ -9139,17 +9150,27 @@ CDocument.prototype =
                     if (false === this.Document_Is_SelectionLocked(CheckType))
                     {
                         this.Create_NewHistoryPoint();
-                        if (e.ShiftKey)
-                        {
-                            this.Paragraph_Add(new ParaNewLine(break_Line));
-                        }
-                        else if (e.CtrlKey)
+
+                        var oSelectedInfo = this.Get_SelectedElementsInfo();
+                        var oMath = oSelectedInfo.Get_Math();
+                        if (null !== oMath && oMath.Is_InInnerContent())
                         {
-                            this.Paragraph_Add(new ParaNewLine(break_Page));
+                            oMath.Handle_AddNewLine();
                         }
                         else
                         {
-                            this.Add_NewParagraph();
+                            if (e.ShiftKey)
+                            {
+                                this.Paragraph_Add(new ParaNewLine(break_Line));
+                            }
+                            else if (e.CtrlKey)
+                            {
+                                this.Paragraph_Add(new ParaNewLine(break_Page));
+                            }
+                            else
+                            {
+                                this.Add_NewParagraph();
+                            }
                         }
                     }
                 }
@@ -9190,23 +9211,36 @@ CDocument.prototype =
             if ( false === this.Document_Is_SelectionLocked(changestype_Paragraph_Content) )
             {
                 this.Create_NewHistoryPoint();
-                if ( true === e.ShiftKey && true === e.CtrlKey )
-                {
-                    this.DrawingDocument.TargetStart();
-                    this.DrawingDocument.TargetShow();
 
-                    this.Paragraph_Add( new ParaText(String.fromCharCode(0x00A0)) );
-                }
-                else if ( true === e.CtrlKey )
+                // Если мы находимся в формуле, тогда пытаемся выполнить автозамену
+
+                var oSelectedInfo = this.Get_SelectedElementsInfo();
+                var oMath = oSelectedInfo.Get_Math();
+
+                if (null !== oMath && true === oMath.Make_AutoCorrect())
                 {
-                    this.Paragraph_ClearFormatting();
+                    // Ничего тут не делаем. Все делается в автозамене
                 }
                 else
                 {
-                    this.DrawingDocument.TargetStart();
-                    this.DrawingDocument.TargetShow();
+                    if (true === e.ShiftKey && true === e.CtrlKey)
+                    {
+                        this.DrawingDocument.TargetStart();
+                        this.DrawingDocument.TargetShow();
+
+                        this.Paragraph_Add(new ParaText(String.fromCharCode(0x00A0)));
+                    }
+                    else if (true === e.CtrlKey)
+                    {
+                        this.Paragraph_ClearFormatting();
+                    }
+                    else
+                    {
+                        this.DrawingDocument.TargetStart();
+                        this.DrawingDocument.TargetShow();
 
-                    this.Paragraph_Add(new ParaSpace());
+                        this.Paragraph_Add(new ParaSpace());
+                    }
                 }
             }
 
diff --git a/Word/Editor/Math.js b/Word/Editor/Math.js
index c6199ffc1..8b14378e4 100644
--- a/Word/Editor/Math.js
+++ b/Word/Editor/Math.js
@@ -1621,3 +1621,42 @@ ParaMath.prototype.Get_ContentSelection = function()
     return {X : oContent.pos.x + this.X, Y : oContent.pos.y + this.Y, W : oContent.size.width, H : oContent.size.height};
 };
 
+/**
+ * Проверяем находимся ли мы во внутреннем (не самом верхнем) контенте формулы.
+ */
+ParaMath.prototype.Is_InInnerContent = function()
+{
+    var oContent = this.GetSelectContent().Content;
+
+    if (oContent.bRoot)
+        return false;
+
+    return true;
+};
+
+/**
+ * Обработка нажатия Enter внутри формулы
+ */
+ParaMath.prototype.Handle_AddNewLine = function()
+{
+};
+
+/**
+ * Разделение формулы на 2 части в заданной позиции. В текущем объекте остается левая часть формулы.
+ * @param ContentPos Позиция
+ * @param Depth
+ * @returns Возвращается правая часть формулы.
+ */
+ParaMath.prototype.Split = function (ContentPos, Depth)
+{
+    return null;
+};
+
+/**
+ * Пытаемся выполнить автозамену в формуле.
+ * @returns {boolean} Выполнилась ли автозамена.
+ */
+ParaMath.prototype.Make_AutoCorrect = function()
+{
+    return false;
+};
diff --git a/Word/Editor/Paragraph.js b/Word/Editor/Paragraph.js
index 771359eb6..440f2554c 100644
--- a/Word/Editor/Paragraph.js
+++ b/Word/Editor/Paragraph.js
@@ -6130,6 +6130,11 @@ Paragraph.prototype =
     Get_SelectedElementsInfo : function(Info)
     {
         Info.Set_Paragraph( this );
+
+        if (true === this.Selection.Use && this.Selection.StartPos === this.Selection.EndPos && para_Math === this.Content[this.Selection.EndPos].Type)
+            Info.Set_Math(this.Content[this.Selection.EndPos]);
+        else (false === this.Selection.Use && para_Math === this.Content[this.CurPos.ContentPos].Type)
+            Info.Set_Math(this.Content[this.CurPos.ContentPos]);
     },
 
     Get_SelectedContent : function(DocContent)
diff --git a/Word/Editor/Paragraph_Recalculate.js b/Word/Editor/Paragraph_Recalculate.js
index e9bf48427..a4e772f68 100644
--- a/Word/Editor/Paragraph_Recalculate.js
+++ b/Word/Editor/Paragraph_Recalculate.js
@@ -415,7 +415,7 @@ Paragraph.prototype.private_RecalculateFastRange       = function(CurRange, CurL
         if ( para_Math === Item.Type )
         {
             // TODO: Надо бы перенести эту проверку на изменение контента параграфа
-            Item.MathPara = this.Check_MathPara(Pos);
+            Item.SetInline(true === this.Check_MathPara(Pos)? false : true);
         }
 
         PRS.Update_CurPos( Pos, 0 );
@@ -1542,7 +1542,7 @@ Paragraph.prototype.private_RecalculateRange           = function(CurRange, CurL
         if ( para_Math === Item.Type )
         {
             // TODO: Надо бы перенести эту проверку на изменение контента параграфа
-            Item.MathPara = this.Check_MathPara(Pos);
+            Item.SetInline(true === this.Check_MathPara(Pos)? false : true);
         }
 
         if ( ( 0 === Pos && 0 === CurLine && 0 === CurRange ) || Pos !== StartPos )
-- 
2.30.9