Commit 7abc9f18 authored by SergeyLuzyanin's avatar SergeyLuzyanin

paste simple text to equations

parent 7065b77b
...@@ -1504,6 +1504,7 @@ ...@@ -1504,6 +1504,7 @@
{ {
var NearPos = {Paragraph: paragraph, ContentPos: paragraph.Get_ParaContentPos(false, false)}; var NearPos = {Paragraph: paragraph, ContentPos: paragraph.Get_ParaContentPos(false, false)};
selectedContent.On_EndCollectElements(target_doc_content, false);
NearPos = { Paragraph: paragraph, ContentPos: paragraph.Get_ParaContentPos(false, false) }; NearPos = { Paragraph: paragraph, ContentPos: paragraph.Get_ParaContentPos(false, false) };
paragraph.Check_NearestPos(NearPos); paragraph.Check_NearestPos(NearPos);
...@@ -1520,25 +1521,63 @@ ...@@ -1520,25 +1521,63 @@
if (1 !== selectedContent.Elements.length || type_Paragraph !== Element.Get_Type() || null === LastClass.Parent) if (1 !== selectedContent.Elements.length || type_Paragraph !== Element.Get_Type() || null === LastClass.Parent)
return; return;
if(!selectedContent.CanConvertToMath) {
var Math = null; var Math = null;
var Count = Element.Content.length; var Count = Element.Content.length;
for (var Index = 0; Index < Count; Index++) for (var Index = 0; Index < Count; Index++) {
{
var Item = Element.Content[Index]; var Item = Element.Content[Index];
if (para_Math === Item.Type && null === Math) if (para_Math === Item.Type && null === Math)
Math = Element.Content[Index]; Math = Element.Content[Index];
else if (true !== Item.Is_Empty({SkipEnd : true})) else if (true !== Item.Is_Empty({SkipEnd: true}))
return; return;
} }
} }
}
else if (para_Run !== LastClass.Type) else if (para_Run !== LastClass.Type)
return; return;
if (null === paragraph.Parent || undefined === paragraph.Parent) if (null === paragraph.Parent || undefined === paragraph.Parent)
return; return;
var Para = NearPos.Paragraph;
var ParaNearPos = Para.Get_ParaNearestPos(NearPos);
var LastClass = ParaNearPos.Classes[ParaNearPos.Classes.length - 1];
var bInsertMath = false;
if (para_Math_Run === LastClass.Type)
{
var MathRun = LastClass;
var NewMathRun = MathRun.Split(ParaNearPos.NearPos.ContentPos, ParaNearPos.Classes.length - 1);
var MathContent = ParaNearPos.Classes[ParaNearPos.Classes.length - 2];
var MathContentPos = ParaNearPos.NearPos.ContentPos.Data[ParaNearPos.Classes.length - 2];
var Element = selectedContent.Elements[0].Element;
var InsertMathContent = null;
for (var nPos = 0, nParaLen = Element.Content.length; nPos < nParaLen; nPos++)
{
if (para_Math === Element.Content[nPos].Type)
{
InsertMathContent = Element.Content[nPos];
break;
}
}
if(null === InsertMathContent)
{
//try to convert content to ParaMath in simple cases.
InsertMathContent = selectedContent.ConvertToMath();
}
if (null !== InsertMathContent)
{
MathContent.Add_ToContent(MathContentPos + 1, NewMathRun);
MathContent.Insert_MathContent(InsertMathContent.Root, MathContentPos + 1, true);
bInsertMath = true;
}
}
if(!bInsertMath){
paragraph.Check_NearestPos(NearPos); paragraph.Check_NearestPos(NearPos);
target_doc_content.Insert_Content(selectedContent, NearPos); target_doc_content.Insert_Content(selectedContent, NearPos);
}
worksheet.objectRender.controller.cursorMoveRight(false, false); worksheet.objectRender.controller.cursorMoveRight(false, false);
......
...@@ -2119,7 +2119,50 @@ PasteProcessor.prototype = ...@@ -2119,7 +2119,50 @@ PasteProcessor.prototype =
return; return;
} }
var bPasteMath = false;
if(this.pasteInExcel)
{
var Para = NearPos.Paragraph;
var ParaNearPos = Para.Get_ParaNearestPos(NearPos);
var LastClass = ParaNearPos.Classes[ParaNearPos.Classes.length - 1];
if (para_Math_Run === LastClass.Type)
{
var MathRun = LastClass;
var NewMathRun = MathRun.Split(ParaNearPos.NearPos.ContentPos, ParaNearPos.Classes.length - 1);
var MathContent = ParaNearPos.Classes[ParaNearPos.Classes.length - 2];
var MathContentPos = ParaNearPos.NearPos.ContentPos.Data[ParaNearPos.Classes.length - 2];
var Element = oSelectedContent.Elements[0].Element;
var InsertMathContent = null;
for (var nPos = 0, nParaLen = Element.Content.length; nPos < nParaLen; nPos++)
{
if (para_Math === Element.Content[nPos].Type)
{
InsertMathContent = Element.Content[nPos];
break;
}
}
if(null === InsertMathContent)
{
//try to convert content to ParaMath in simple cases.
InsertMathContent = oSelectedContent.ConvertToMath();
}
if (null !== InsertMathContent)
{
MathContent.Add_ToContent(MathContentPos + 1, NewMathRun);
MathContent.Insert_MathContent(InsertMathContent.Root, MathContentPos + 1, true);
bPasteMath = true;
}
}
}
if(!bPasteMath)
{
paragraph.Parent.Insert_Content(oSelectedContent, NearPos); paragraph.Parent.Insert_Content(oSelectedContent, NearPos);
}
if(oSelectedContent.Elements.length === 1) if(oSelectedContent.Elements.length === 1)
{ {
......
...@@ -4786,6 +4786,7 @@ CPresentation.prototype = ...@@ -4786,6 +4786,7 @@ CPresentation.prototype =
} }
else if(Content.DocContent) else if(Content.DocContent)
{ {
Content.DocContent.On_EndCollectElements(this, false);
if(Content.DocContent.Elements.length > 0){ if(Content.DocContent.Elements.length > 0){
var oController = this.GetCurrentController(); var oController = this.GetCurrentController();
var target_doc_content = oController.getTargetDocContent(true), paragraph, NearPos; var target_doc_content = oController.getTargetDocContent(true), paragraph, NearPos;
...@@ -4813,18 +4814,18 @@ CPresentation.prototype = ...@@ -4813,18 +4814,18 @@ CPresentation.prototype =
var Element = Content.DocContent.Elements[0].Element; var Element = Content.DocContent.Elements[0].Element;
if (1 !== Content.DocContent.Elements.length || type_Paragraph !== Element.Get_Type() || null === LastClass.Parent) if (1 !== Content.DocContent.Elements.length || type_Paragraph !== Element.Get_Type() || null === LastClass.Parent)
return; return;
if(!Content.DocContent.CanConvertToMath) {
var Math = null; var Math = null;
var Count = Element.Content.length; var Count = Element.Content.length;
for (var Index = 0; Index < Count; Index++) for (var Index = 0; Index < Count; Index++) {
{
var Item = Element.Content[Index]; var Item = Element.Content[Index];
if (para_Math === Item.Type && null === Math) if (para_Math === Item.Type && null === Math)
Math = Element.Content[Index]; Math = Element.Content[Index];
else if (true !== Item.Is_Empty({SkipEnd : true})) else if (true !== Item.Is_Empty({SkipEnd: true}))
return; return;
} }
} }
}
else if (para_Run !== LastClass.Type) else if (para_Run !== LastClass.Type)
return; return;
...@@ -4832,7 +4833,42 @@ CPresentation.prototype = ...@@ -4832,7 +4833,42 @@ CPresentation.prototype =
return; return;
target_doc_content.Insert_Content(Content.DocContent, NearPos); var Para = NearPos.Paragraph;
var ParaNearPos = Para.Get_ParaNearestPos(NearPos);
var LastClass = ParaNearPos.Classes[ParaNearPos.Classes.length - 1];
var bInsertMath = false;
if (para_Math_Run === LastClass.Type)
{
var MathRun = LastClass;
var NewMathRun = MathRun.Split(ParaNearPos.NearPos.ContentPos, ParaNearPos.Classes.length - 1);
var MathContent = ParaNearPos.Classes[ParaNearPos.Classes.length - 2];
var MathContentPos = ParaNearPos.NearPos.ContentPos.Data[ParaNearPos.Classes.length - 2];
var Element = Content.DocContent.Elements[0].Element;
var InsertMathContent = null;
for (var nPos = 0, nParaLen = Element.Content.length; nPos < nParaLen; nPos++)
{
if (para_Math === Element.Content[nPos].Type)
{
InsertMathContent = Element.Content[nPos];
break;
}
}
if(null === InsertMathContent)
{
//try to convert content to ParaMath in simple cases.
InsertMathContent = Content.DocContent.ConvertToMath();
}
if (null !== InsertMathContent)
{
MathContent.Add_ToContent(MathContentPos + 1, NewMathRun);
MathContent.Insert_MathContent(InsertMathContent.Root, MathContentPos + 1, true);
bInsertMath = true;
}
}
!bInsertMath && target_doc_content.Insert_Content(Content.DocContent, NearPos);
} }
var oTargetTextObject = AscFormat.getTargetTextObject(this.Slides[this.CurPage].graphicObjects); var oTargetTextObject = AscFormat.getTargetTextObject(this.Slides[this.CurPage].graphicObjects);
oTargetTextObject && oTargetTextObject.checkExtentsByDocContent && oTargetTextObject.checkExtentsByDocContent(); oTargetTextObject && oTargetTextObject.checkExtentsByDocContent && oTargetTextObject.checkExtentsByDocContent();
......
...@@ -347,6 +347,7 @@ function CSelectedContent() ...@@ -347,6 +347,7 @@ function CSelectedContent()
this.HaveShape = false; this.HaveShape = false;
this.MoveDrawing = false; // Только для переноса автофигур this.MoveDrawing = false; // Только для переноса автофигур
this.HaveMath = false; this.HaveMath = false;
this.CanConvertToMath = false;
} }
CSelectedContent.prototype = CSelectedContent.prototype =
...@@ -392,6 +393,20 @@ CSelectedContent.prototype = ...@@ -392,6 +393,20 @@ CSelectedContent.prototype =
this.HaveMath = (this.Maths.length > 0 ? true : false); this.HaveMath = (this.Maths.length > 0 ? true : false);
// Проверка возможности конвертации имеющегося контента в контент для вставки в формулу.
// Если формулы уже имеются, то ничего не конвертируем.
if(!this.HaveMath)
{
if(1 === Count)
{
Element = this.Elements[0];
if(type_Paragraph === Element.Element.GetType() && !Element.Element.Is_Empty({SkipEnd : true, SkipAnchor : true, SkipNewLine: true, SkipPlcHldr: true}) && !Element.SelectedAll )
{
this.CanConvertToMath = true;
}
}
}
// Относительно картинок нас интересует только наличие автофигур с текстом. // Относительно картинок нас интересует только наличие автофигур с текстом.
Count = this.DrawingObjects.length; Count = this.DrawingObjects.length;
for (var Pos = 0; Pos < Count; Pos++) for (var Pos = 0; Pos < Count; Pos++)
...@@ -479,6 +494,36 @@ CSelectedContent.prototype = ...@@ -479,6 +494,36 @@ CSelectedContent.prototype =
} }
} }
} }
},
/**
* Converts current content to ParaMath if it possible. Doesn't change current SelectedContent.
* @returns {?AscCommonWord.ParaMath}
* */
ConvertToMath : function()
{
if(!this.CanConvertToMath)
{
return null;
}
var oParagraph = this.Elements[0].Element;
var aContent = oParagraph.Content, aRunContent;
var oParaMath = new AscCommonWord.ParaMath();
oParaMath.Root.Load_FromMenu(c_oAscMathType.Default_Text, oParagraph);
oParaMath.Root.Correct_Content(true);
for(var i = 0; i < aContent.length; ++i)
{
if(aContent[i].Get_Type() === para_Run)
{
aRunContent = aContent[i].Content;
for(var j = 0; j < aRunContent.length; ++j)
{
oParaMath.Add(aRunContent[j]);
}
}
}
return oParaMath;
} }
}; };
...@@ -5729,17 +5774,19 @@ CDocument.prototype.Can_InsertContent = function(SelectedContent, NearPos) ...@@ -5729,17 +5774,19 @@ CDocument.prototype.Can_InsertContent = function(SelectedContent, NearPos)
if (1 !== SelectedContent.Elements.length || type_Paragraph !== Element.GetType() || null === LastClass.Parent) if (1 !== SelectedContent.Elements.length || type_Paragraph !== Element.GetType() || null === LastClass.Parent)
return false; return false;
if(!SelectedContent.CanConvertToMath)
{
var Math = null; var Math = null;
var Count = Element.Content.length; var Count = Element.Content.length;
for (var Index = 0; Index < Count; Index++) for (var Index = 0; Index < Count; Index++) {
{
var Item = Element.Content[Index]; var Item = Element.Content[Index];
if (para_Math === Item.Type && null === Math) if (para_Math === Item.Type && null === Math)
Math = Element.Content[Index]; Math = Element.Content[Index];
else if (true !== Item.Is_Empty({SkipEnd : true})) else if (true !== Item.Is_Empty({SkipEnd: true}))
return false; return false;
} }
} }
}
else if (para_Run !== LastClass.Type) else if (para_Run !== LastClass.Type)
return false; return false;
...@@ -5771,6 +5818,12 @@ CDocument.prototype.Insert_Content = function(SelectedContent, NearPos) ...@@ -5771,6 +5818,12 @@ CDocument.prototype.Insert_Content = function(SelectedContent, NearPos)
} }
} }
if(null === InsertMathContent)
{
//try to convert content to ParaMath in simple cases.
InsertMathContent = SelectedContent.ConvertToMath();
}
if (null !== InsertMathContent) if (null !== InsertMathContent)
{ {
MathContent.Add_ToContent(MathContentPos + 1, NewMathRun); MathContent.Add_ToContent(MathContentPos + 1, NewMathRun);
......
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