starmath/source/edit.cxx |   40 +++++++++++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 7 deletions(-)

New commits:
commit 467d5e0a2e074ff2afb4d1b1a37cff2094b0895b
Author: Marcos Paulo de Souza <marcos.souza....@gmail.com>
Date:   Mon May 20 23:26:18 2013 -0300

    Fix fdo#32059: Commands merge with variables
    
    Co-work with Rodolfo Ribeiro Gomes <rodolf...@gmail.com>. Thanks a lot man!
    
    Verify if there is a space before insert a new command to not merge
    variables.
    
    Also, just make atributions in EndPos when it is needed, to make this more 
clear.
    
    Change-Id: Ia5ddb4c4c8233b3779c0ee0c7009e181cfe5d1c3
    Reviewed-on: https://gerrit.libreoffice.org/3983
    Reviewed-by: Luboš Luňák <l.lu...@suse.cz>
    Tested-by: Luboš Luňák <l.lu...@suse.cz>

diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx
index fc88ba7..f68e0fb 100644
--- a/starmath/source/edit.cxx
+++ b/starmath/source/edit.cxx
@@ -706,25 +706,50 @@ void SmEditWindow::InsertCommand(sal_uInt16 nCommand)
     OSL_ENSURE( pEditView, "EditView missing" );
     if (pEditView)
     {
-        // Remember start of the selection and move the cursor there 
afterwards.
-        // Only this way the SelNextMark() makes sense...
         ESelection aSelection = pEditView->GetSelection();
-        aSelection.nEndPos  = aSelection.nStartPos;
-        aSelection.nEndPara = aSelection.nStartPara;
 
         OSL_ENSURE( pEditView, "NULL pointer" );
         OUString aText = SM_RESSTR(nCommand);
+
+        OUString aCurrentFormula = pEditView->GetEditEngine()->GetText();
+        sal_Int32 nStartIndex = 0;
+        sal_Int32 nEndIndex = 0;
+
+        // get the start position (when we get a multi line formula)
+        for (sal_Int32 nParaPos = 0; nParaPos < aSelection.nStartPara; 
nParaPos++)
+             nStartIndex = aCurrentFormula.indexOf("\n", nStartIndex) + 1;
+
+        nStartIndex += aSelection.nStartPos;
+
+        // get the end position (when we get a multi line formula)
+        for (sal_Int32 nParaPos = 0; nParaPos < aSelection.nEndPara; 
nParaPos++)
+             nEndIndex = aCurrentFormula.indexOf("\n", nEndIndex) + 1;
+
+        nEndIndex += aSelection.nEndPos;
+
+        // remove right space of current symbol if there already one
+        if (nEndIndex < aCurrentFormula.getLength() &&
+            aCurrentFormula[nEndIndex] == ' ')
+            aText = aText.trim();
+
+        // put an space before put a new command when necessary(if we're not 
in the begin of a line)
+        if (aSelection.nStartPos > 0 && aCurrentFormula[nStartIndex - 1] != ' 
')
+            aText = " " + aText;
+
         pEditView->InsertText(aText);
 
+        // Remember start of the selection and move the cursor there 
afterwards.
+        aSelection.nEndPara = aSelection.nStartPara;
         if (HasMark(aText))
-        {   // set selection to next mark
+        {
+            aSelection.nEndPos = aSelection.nStartPos;
             pEditView->SetSelection(aSelection);
             SelNextMark();
         }
         else
         {   // set selection after inserted text
-            aSelection.nEndPos += aText.getLength();
-            aSelection.nStartPos  = aSelection.nEndPos;
+            aSelection.nEndPos = aSelection.nStartPos + aText.getLength();
+            aSelection.nStartPos = aSelection.nEndPos;
             pEditView->SetSelection(aSelection);
         }
 
@@ -747,6 +772,7 @@ void SmEditWindow::MarkError(const Point &rPos)
     }
 }
 
+// Makes selection to next <?> symbol
 void SmEditWindow::SelNextMark()
 {
     EditEngine *pEditEngine = GetEditEngine();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to