summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcos Paulo de Souza <marcos.souza.org@gmail.com>2013-05-20 23:26:18 -0300
committerLuboš Luňák <l.lunak@suse.cz>2013-05-31 18:10:47 +0000
commit467d5e0a2e074ff2afb4d1b1a37cff2094b0895b (patch)
tree120f7453d30935a44b9bc19ed9f9e902bb968364
parent660b67a413fed152bc273bdc534e53b01b1e9d77 (diff)
Fix fdo#32059: Commands merge with variables
Co-work with Rodolfo Ribeiro Gomes <rodolforg@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.lunak@suse.cz> Tested-by: Luboš Luňák <l.lunak@suse.cz>
-rw-r--r--starmath/source/edit.cxx40
1 files changed, 33 insertions, 7 deletions
diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx
index fc88ba7cca3d..f68e0fb36d8f 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();