diff options
author | Hrishabh <rajputhrishabh@gmail.com> | 2018-03-10 14:13:06 +0530 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2018-04-13 14:21:23 +0200 |
commit | f17a04df424dac553195c1922a4e4aa1f4ad5b9d (patch) | |
tree | 5af1fab510654691a61dcd07e9fe3bb9b8ae5126 | |
parent | 1670f6aaf28907403e5305b78ebcf93de4ebc19b (diff) |
tdf#39593 fixed copy paste code in sw edlingu.cxx
Change-Id: I5d4909e7c16aee488971b4793b20a5cf3ae6bddf
Reviewed-on: https://gerrit.libreoffice.org/51173
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
-rw-r--r-- | sw/inc/editsh.hxx | 3 | ||||
-rw-r--r-- | sw/source/core/edit/edlingu.cxx | 150 |
2 files changed, 59 insertions, 94 deletions
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index 8b9e5662fbe6..3a7ecbd9e030 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -791,6 +791,9 @@ public: /// Is hyphenation active somewhere else? static bool HasHyphIter(); + void HandleCorrectionError( const OUString aText, SwPosition aPos, + sal_Int32 nBegin, sal_Int32 nLen, SwPaM* pCursor, + const Point* pPt, SwRect& rSelectRect ); css::uno::Reference< css::linguistic2::XSpellAlternatives > GetCorrection( const Point* pPt, SwRect& rSelectRect ); diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx index c4f602ce0e36..74401bb03f05 100644 --- a/sw/source/core/edit/edlingu.cxx +++ b/sw/source/core/edit/edlingu.cxx @@ -815,6 +815,60 @@ void SwEditShell::HyphIgnore() g_pHyphIter->ShowSelection(); } +void SwEditShell::HandleCorrectionError( + const OUString aText, SwPosition aPos, sal_Int32 nBegin, + sal_Int32 nLen, SwPaM* pCursor, + const Point* pPt, SwRect& rSelectRect ) +{ + // save the start and end positions of the line and the starting point + Push(); + LeftMargin(); + const sal_Int32 nLineStart = GetCursor()->GetPoint()->nContent.GetIndex(); + RightMargin(); + const sal_Int32 nLineEnd = GetCursor()->GetPoint()->nContent.GetIndex(); + Pop(PopMode::DeleteCurrent); + + // make sure the selection build later from the data below does + // not "in word" character to the left and right in order to + // preserve those. Therefore count those "in words" in order to + // modify the selection accordingly. + const sal_Unicode* pChar = aText.getStr(); + sal_Int32 nLeft = 0; + while (*pChar++ == CH_TXTATR_INWORD) + ++nLeft; + pChar = aText.getLength() ? aText.getStr() + aText.getLength() - 1 : nullptr; + sal_Int32 nRight = 0; + while (pChar && *pChar-- == CH_TXTATR_INWORD) + ++nRight; + + aPos.nContent = nBegin + nLeft; + pCursor = GetCursor(); + *pCursor->GetPoint() = aPos; + pCursor->SetMark(); + ExtendSelection( true, nLen - nLeft - nRight ); + // don't determine the rectangle in the current line + const sal_Int32 nWordStart = (nBegin + nLeft) < nLineStart ? nLineStart : nBegin + nLeft; + // take one less than the line end - otherwise the next line would be calculated + const sal_Int32 nWordEnd = (nBegin + nLen - nLeft - nRight) > nLineEnd + ? nLineEnd : (nBegin + nLen - nLeft - nRight); + Push(); + pCursor->DeleteMark(); + SwIndex& rContent = GetCursor()->GetPoint()->nContent; + rContent = nWordStart; + SwRect aStartRect; + SwCursorMoveState aState; + aState.m_bRealWidth = true; + SwContentNode* pContentNode = pCursor->GetContentNode(); + SwContentFrame *pContentFrame = pContentNode->getLayoutFrame( GetLayout(), pPt, pCursor->GetPoint(), false); + + pContentFrame->GetCharRect( aStartRect, *pCursor->GetPoint(), &aState ); + rContent = nWordEnd - 1; + SwRect aEndRect; + pContentFrame->GetCharRect( aEndRect, *pCursor->GetPoint(),&aState ); + rSelectRect = aStartRect.Union( aEndRect ); + Pop(PopMode::DeleteCurrent); +} + /** Get a list of potential corrections for misspelled word. * * If empty, word is unknown but there are no corrections available. @@ -877,53 +931,7 @@ uno::Reference< XSpellAlternatives > if ( xSpellAlt.is() ) // error found? { - // save the start and end positions of the line and the starting point - Push(); - LeftMargin(); - const sal_Int32 nLineStart = GetCursor()->GetPoint()->nContent.GetIndex(); - RightMargin(); - const sal_Int32 nLineEnd = GetCursor()->GetPoint()->nContent.GetIndex(); - Pop(PopMode::DeleteCurrent); - - // make sure the selection build later from the data below does - // not "in word" character to the left and right in order to - // preserve those. Therefore count those "in words" in order to - // modify the selection accordingly. - const sal_Unicode* pChar = aText.getStr(); - sal_Int32 nLeft = 0; - while (*pChar++ == CH_TXTATR_INWORD) - ++nLeft; - pChar = aText.getLength() ? aText.getStr() + aText.getLength() - 1 : nullptr; - sal_Int32 nRight = 0; - while (pChar && *pChar-- == CH_TXTATR_INWORD) - ++nRight; - - aPos.nContent = nBegin + nLeft; - pCursor = GetCursor(); - *pCursor->GetPoint() = aPos; - pCursor->SetMark(); - ExtendSelection( true, nLen - nLeft - nRight ); - // don't determine the rectangle in the current line - const sal_Int32 nWordStart = (nBegin + nLeft) < nLineStart ? nLineStart : nBegin + nLeft; - // take one less than the line end - otherwise the next line would be calculated - const sal_Int32 nWordEnd = (nBegin + nLen - nLeft - nRight) > nLineEnd - ? nLineEnd : (nBegin + nLen - nLeft - nRight); - Push(); - pCursor->DeleteMark(); - SwIndex& rContent = GetCursor()->GetPoint()->nContent; - rContent = nWordStart; - SwRect aStartRect; - SwCursorMoveState aState; - aState.m_bRealWidth = true; - SwContentNode* pContentNode = pCursor->GetContentNode(); - SwContentFrame *pContentFrame = pContentNode->getLayoutFrame( GetLayout(), pPt, pCursor->GetPoint(), false); - - pContentFrame->GetCharRect( aStartRect, *pCursor->GetPoint(), &aState ); - rContent = nWordEnd - 1; - SwRect aEndRect; - pContentFrame->GetCharRect( aEndRect, *pCursor->GetPoint(),&aState ); - rSelectRect = aStartRect.Union( aEndRect ); - Pop(PopMode::DeleteCurrent); + HandleCorrectionError( aText, aPos, nBegin, nLen, pCursor, pPt, rSelectRect ); } } } @@ -1002,53 +1010,7 @@ bool SwEditShell::GetGrammarCorrection( if (rResult.aErrors.getLength() > 0) // error found? { - // save the start and end positions of the line and the starting point - Push(); - LeftMargin(); - const sal_Int32 nLineStart = GetCursor()->GetPoint()->nContent.GetIndex(); - RightMargin(); - const sal_Int32 nLineEnd = GetCursor()->GetPoint()->nContent.GetIndex(); - Pop(PopMode::DeleteCurrent); - - // make sure the selection build later from the data below does - // not include "in word" character to the left and right in - // order to preserve those. Therefore count those "in words" in - // order to modify the selection accordingly. - const sal_Unicode* pChar = aText.getStr(); - sal_Int32 nLeft = 0; - while (*pChar++ == CH_TXTATR_INWORD) - ++nLeft; - pChar = aText.getLength() ? aText.getStr() + aText.getLength() - 1 : nullptr; - sal_Int32 nRight = 0; - while (pChar && *pChar-- == CH_TXTATR_INWORD) - ++nRight; - - aPos.nContent = nBegin + nLeft; - pCursor = GetCursor(); - *pCursor->GetPoint() = aPos; - pCursor->SetMark(); - ExtendSelection( true, nLen - nLeft - nRight ); - // don't determine the rectangle in the current line - const sal_Int32 nWordStart = (nBegin + nLeft) < nLineStart ? nLineStart : nBegin + nLeft; - // take one less than the line end - otherwise the next line would be calculated - const sal_Int32 nWordEnd = (nBegin + nLen - nLeft - nRight) > nLineEnd - ? nLineEnd : (nBegin + nLen - nLeft - nRight); - Push(); - pCursor->DeleteMark(); - SwIndex& rContent = GetCursor()->GetPoint()->nContent; - rContent = nWordStart; - SwRect aStartRect; - SwCursorMoveState aState; - aState.m_bRealWidth = true; - SwContentNode* pContentNode = pCursor->GetContentNode(); - SwContentFrame *pContentFrame = pContentNode->getLayoutFrame( GetLayout(), pPt, pCursor->GetPoint(), false); - - pContentFrame->GetCharRect( aStartRect, *pCursor->GetPoint(), &aState ); - rContent = nWordEnd - 1; - SwRect aEndRect; - pContentFrame->GetCharRect( aEndRect, *pCursor->GetPoint(),&aState ); - rSelectRect = aStartRect.Union( aEndRect ); - Pop(PopMode::DeleteCurrent); + HandleCorrectionError( aText, aPos, nBegin, nLen, pCursor, pPt, rSelectRect ); } } } |