Commit 7abc9f18 authored by SergeyLuzyanin's avatar SergeyLuzyanin

paste simple text to equations

parent 7065b77b
......@@ -1504,6 +1504,7 @@
{
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) };
paragraph.Check_NearestPos(NearPos);
......@@ -1520,15 +1521,16 @@
if (1 !== selectedContent.Elements.length || type_Paragraph !== Element.Get_Type() || null === LastClass.Parent)
return;
var Math = null;
var Count = Element.Content.length;
for (var Index = 0; Index < Count; Index++)
{
var Item = Element.Content[Index];
if (para_Math === Item.Type && null === Math)
Math = Element.Content[Index];
else if (true !== Item.Is_Empty({SkipEnd : true}))
return;
if(!selectedContent.CanConvertToMath) {
var Math = null;
var Count = Element.Content.length;
for (var Index = 0; Index < Count; Index++) {
var Item = Element.Content[Index];
if (para_Math === Item.Type && null === Math)
Math = Element.Content[Index];
else if (true !== Item.Is_Empty({SkipEnd: true}))
return;
}
}
}
else if (para_Run !== LastClass.Type)
......@@ -1537,8 +1539,45 @@
if (null === paragraph.Parent || undefined === paragraph.Parent)
return;
paragraph.Check_NearestPos(NearPos);
target_doc_content.Insert_Content(selectedContent, 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 = 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);
target_doc_content.Insert_Content(selectedContent, NearPos);
}
worksheet.objectRender.controller.cursorMoveRight(false, false);
......
......@@ -2119,9 +2119,52 @@ PasteProcessor.prototype =
return;
}
paragraph.Parent.Insert_Content(oSelectedContent, NearPos);
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);
}
if(oSelectedContent.Elements.length === 1)
if(oSelectedContent.Elements.length === 1)
{
var curDocSelection = this.curDocSelection;
if(curDocSelection)
......
......@@ -4786,6 +4786,7 @@ CPresentation.prototype =
}
else if(Content.DocContent)
{
Content.DocContent.On_EndCollectElements(this, false);
if(Content.DocContent.Elements.length > 0){
var oController = this.GetCurrentController();
var target_doc_content = oController.getTargetDocContent(true), paragraph, NearPos;
......@@ -4813,16 +4814,16 @@ CPresentation.prototype =
var Element = Content.DocContent.Elements[0].Element;
if (1 !== Content.DocContent.Elements.length || type_Paragraph !== Element.Get_Type() || null === LastClass.Parent)
return;
var Math = null;
var Count = Element.Content.length;
for (var Index = 0; Index < Count; Index++)
{
var Item = Element.Content[Index];
if (para_Math === Item.Type && null === Math)
Math = Element.Content[Index];
else if (true !== Item.Is_Empty({SkipEnd : true}))
return;
if(!Content.DocContent.CanConvertToMath) {
var Math = null;
var Count = Element.Content.length;
for (var Index = 0; Index < Count; Index++) {
var Item = Element.Content[Index];
if (para_Math === Item.Type && null === Math)
Math = Element.Content[Index];
else if (true !== Item.Is_Empty({SkipEnd: true}))
return;
}
}
}
else if (para_Run !== LastClass.Type)
......@@ -4832,7 +4833,42 @@ CPresentation.prototype =
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);
oTargetTextObject && oTargetTextObject.checkExtentsByDocContent && oTargetTextObject.checkExtentsByDocContent();
......
......@@ -344,9 +344,10 @@ function CSelectedContent()
this.Comments = [];
this.Maths = [];
this.HaveShape = false;
this.MoveDrawing = false; // Только для переноса автофигур
this.HaveMath = false;
this.HaveShape = false;
this.MoveDrawing = false; // Только для переноса автофигур
this.HaveMath = false;
this.CanConvertToMath = false;
}
CSelectedContent.prototype =
......@@ -392,6 +393,20 @@ CSelectedContent.prototype =
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;
for (var Pos = 0; Pos < Count; Pos++)
......@@ -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,16 +5774,18 @@ CDocument.prototype.Can_InsertContent = function(SelectedContent, NearPos)
if (1 !== SelectedContent.Elements.length || type_Paragraph !== Element.GetType() || null === LastClass.Parent)
return false;
var Math = null;
var Count = Element.Content.length;
for (var Index = 0; Index < Count; Index++)
{
var Item = Element.Content[Index];
if (para_Math === Item.Type && null === Math)
Math = Element.Content[Index];
else if (true !== Item.Is_Empty({SkipEnd : true}))
return false;
}
if(!SelectedContent.CanConvertToMath)
{
var Math = null;
var Count = Element.Content.length;
for (var Index = 0; Index < Count; Index++) {
var Item = Element.Content[Index];
if (para_Math === Item.Type && null === Math)
Math = Element.Content[Index];
else if (true !== Item.Is_Empty({SkipEnd: true}))
return false;
}
}
}
else if (para_Run !== LastClass.Type)
return false;
......@@ -5771,7 +5818,13 @@ CDocument.prototype.Insert_Content = function(SelectedContent, NearPos)
}
}
if (null !== InsertMathContent)
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);
......
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