diff options
author | Michael Duelli <m.duelli@web.de> | 2013-08-01 01:01:57 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2013-08-08 09:11:46 +0000 |
commit | 356b2f0edfd5a01ed05976c1bdb74948ff84b5fd (patch) | |
tree | 321ad3cee32b89bd0370ab68f2804d3243e9b214 /starmath | |
parent | c58f859ee6899bd5066bb754159d06e114405c96 (diff) |
Extension to fix all cases of fdo#32059: Commands merge with variables
Change 467d5e0a2e074ff2afb4d1b1a37cff2094b0895b fixed insertions of
space in front of commands for Elements dialog only.
This change also fixes insertion via Elements dock.
Change-Id: I37f8510bc4a6dc0145026ca04fbb0443e1e31cd0
Reviewed-on: https://gerrit.libreoffice.org/5225
Reviewed-by: Marcos Souza <marcos.souza.org@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@suse.cz>
Tested-by: Miklos Vajna <vmiklos@suse.cz>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/source/edit.cxx | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx index ec9680fdf3e5..2a7cb9395e9e 100644 --- a/starmath/source/edit.cxx +++ b/starmath/source/edit.cxx @@ -755,16 +755,16 @@ void SmEditWindow::InsertCommand(sal_uInt16 nCommand) nEndIndex += aSelection.nEndPos; - // remove right space of current symbol if there already one + // remove right space of current symbol if there already is 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) + // put a space before a new command if not in the beginning of a line if (aSelection.nStartPos > 0 && aCurrentFormula[nStartIndex - 1] != ' ') - aText = " " + aText; - - pEditView->InsertText(aText); + pEditView->InsertText(" " + aText); + else + pEditView->InsertText(aText); // Remember start of the selection and move the cursor there afterwards. aSelection.nEndPara = aSelection.nStartPara; @@ -975,7 +975,30 @@ void SmEditWindow::InsertText(const OUString& rText) OSL_ENSURE( pEditView, "EditView missing" ); if (pEditView) { - pEditView->InsertText(rText); + // Note: Insertion of a space in front of commands is done here and + // in SmEditWindow::InsertCommand. + ESelection aSelection = pEditView->GetSelection(); + 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; + + // put a space before a new command if not in the beginning of a line + if (aSelection.nStartPos > 0 && aCurrentFormula[nStartIndex - 1] != ' ') + pEditView->InsertText(" " + rText); + else + pEditView->InsertText(rText); aModifyTimer.Start(); StartCursorMove(); } |