From f045d14791a84f478c40fbd6b0590f527b36cbff Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Thu, 21 Jul 2016 17:57:28 +0900 Subject: starmath: Return early if the cursor locates after a text node No longer create unnecessary copy of nodes. Change-Id: Icf8cdd3ce0f9ebbf7159e9e7eaea7abe52c05060 Reviewed-on: https://gerrit.libreoffice.org/27366 Tested-by: Jenkins Reviewed-by: Takeshi Abe --- starmath/source/cursor.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'starmath') diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx index bef900af6ed4..b1ef0b0e9495 100644 --- a/starmath/source/cursor.cxx +++ b/starmath/source/cursor.cxx @@ -354,16 +354,17 @@ SmNodeList::iterator SmCursor::FindPositionInLineList(SmNodeList* pLineList, if(rCaretPos.Index > 0) { SmTextNode* pText = static_cast(rCaretPos.pSelectedNode); + if (rCaretPos.Index == pText->GetText().getLength()) + return ++it; OUString str1 = pText->GetText().copy(0, rCaretPos.Index); OUString str2 = pText->GetText().copy(rCaretPos.Index); pText->ChangeText(str1); ++it; //Insert str2 as new text node - if(!str2.isEmpty()){ - SmTextNode* pNewText = new SmTextNode(pText->GetToken(), pText->GetFontDesc()); - pNewText->ChangeText(str2); - it = pLineList->insert(it, pNewText); - } + assert(!str2.isEmpty()); + SmTextNode* pNewText = new SmTextNode(pText->GetToken(), pText->GetFontDesc()); + pNewText->ChangeText(str2); + it = pLineList->insert(it, pNewText); } }else ++it; -- cgit