diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2018-11-27 22:17:40 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-11-29 12:06:44 +0100 |
commit | 0ded54c33f01d18d2cd06547bd8307bd140cf28f (patch) | |
tree | e250a9a8bb89b2042d9a0bc09f80bf65757eec19 /starmath/source/cursor.cxx | |
parent | 7d311ea864e7cfeb1c8f4ca417911db20d13361e (diff) |
Simplify containers iterations in slideshow, sot, starmath, stoc
Use range-based loop or replace with STL functions
Change-Id: I94792c28b283a0998bf813317e5beb37d93e0c23
Reviewed-on: https://gerrit.libreoffice.org/64125
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath/source/cursor.cxx')
-rw-r--r-- | starmath/source/cursor.cxx | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx index a1ada63bede4..a883b679ce2a 100644 --- a/starmath/source/cursor.cxx +++ b/starmath/source/cursor.cxx @@ -340,34 +340,31 @@ SmNodeList::iterator SmCursor::FindPositionInLineList(SmNodeList* pLineList, const SmCaretPos& rCaretPos) { //Find iterator for position - SmNodeList::iterator it; - for(it = pLineList->begin(); it != pLineList->end(); ++it){ - if(*it == rCaretPos.pSelectedNode) + SmNodeList::iterator it = std::find(pLineList->begin(), pLineList->end(), rCaretPos.pSelectedNode); + if (it != pLineList->end()) + { + if((*it)->GetType() == SmNodeType::Text) { - if((*it)->GetType() == SmNodeType::Text) + //Split textnode if needed + if(rCaretPos.nIndex > 0) { - //Split textnode if needed - if(rCaretPos.nIndex > 0) - { - SmTextNode* pText = static_cast<SmTextNode*>(rCaretPos.pSelectedNode); - if (rCaretPos.nIndex == pText->GetText().getLength()) - return ++it; - OUString str1 = pText->GetText().copy(0, rCaretPos.nIndex); - OUString str2 = pText->GetText().copy(rCaretPos.nIndex); - pText->ChangeText(str1); - ++it; - //Insert str2 as new text node - assert(!str2.isEmpty()); - SmTextNode* pNewText = new SmTextNode(pText->GetToken(), pText->GetFontDesc()); - pNewText->ChangeText(str2); - it = pLineList->insert(it, pNewText); - } - }else + SmTextNode* pText = static_cast<SmTextNode*>(rCaretPos.pSelectedNode); + if (rCaretPos.nIndex == pText->GetText().getLength()) + return ++it; + OUString str1 = pText->GetText().copy(0, rCaretPos.nIndex); + OUString str2 = pText->GetText().copy(rCaretPos.nIndex); + pText->ChangeText(str1); ++it; - //it now pointer to the node following pos, so pLineList->insert(it, ...) will insert correctly - return it; - - } + //Insert str2 as new text node + assert(!str2.isEmpty()); + SmTextNode* pNewText = new SmTextNode(pText->GetToken(), pText->GetFontDesc()); + pNewText->ChangeText(str2); + it = pLineList->insert(it, pNewText); + } + }else + ++it; + //it now pointer to the node following pos, so pLineList->insert(it, ...) will insert correctly + return it; } //If we didn't find pSelectedNode, it must be because the caret is in front of the line return pLineList->begin(); |