tdf#141198 sw: fix cycle case with change tracking

Fix cycle case with change tracking by rejecting
changes of the word, and setting the cursor inside
the original word.

Previously the cycle case resulted only in a tracked
deletion and tracked insertion, putting the text
cursor at after the word, so it was not possible to
cycle on the different cases e.g. by pressing Shift-F3
multiple times (and moving the text cursor inside
the tracked insertion didn't help, because resulted
in broken text at asking for the next cycle).

A regression from commit 2d3c77e9b10f20091ef338e262ba7756eb280ce9
"tdf#109266 sw change tracking: track transliteration".

Change-Id: I819cf0ec722d54852bfc31f7765e0f06e2a07fd3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157303
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit dc748d7dbd114fbf663752258dbaf003af2926c3)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157321
Tested-by: Jenkins
Reviewed-by: Patrick Luby <plubius@neooffice.org>
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index f7d24dd..47e5b818 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#include <DocumentContentOperationsManager.hxx>
#include <DocumentRedlineManager.hxx>
#include <wrtsh.hxx>
#include <doc.hxx>
#include <IDocumentUndoRedo.hxx>
#include <IDocumentMarkAccess.hxx>
@@ -2999,6 +3001,38 @@ void DocumentContentOperationsManager::TransliterateText(
            }
        } else {
            /* Cursor is not inside of a word. Nothing should happen. */
            /* Except in the case of change tracking, when the cursor is at the end of the change */
            /* Recognize and reject the previous deleted and inserted words to allow to cycle */
            IDocumentRedlineAccess& rIDRA = m_rDoc.getIDocumentRedlineAccess();
            if ( IDocumentRedlineAccess::IsShowChanges( rIDRA.GetRedlineFlags() ) &&
                            pStt->GetContentIndex() > 0 )
            {
                SwPosition aPos(*pStt->GetContentNode(), pStt->GetContentIndex() - 1);
                SwRedlineTable::size_type n = 0;

                const SwRangeRedline* pFnd =
                                    rIDRA.GetRedlineTable().FindAtPosition( aPos, n );
                if ( pFnd && RedlineType::Insert == pFnd->GetType() && n > 0 )
                {
                    const SwRangeRedline* pFnd2 = rIDRA.GetRedlineTable()[n-1];
                    if ( RedlineType::Delete == pFnd2->GetType() &&
                          m_rDoc.getIDocumentLayoutAccess().GetCurrentViewShell() &&
                          *pFnd2->End() == *pFnd->Start() &&
                          pFnd->GetAuthor() == pFnd2->GetAuthor() )
                    {
                        SwPosition aPos2(*pFnd2->End());
                        rIDRA.RejectRedline(*pFnd, true);
                        rIDRA.RejectRedline(*pFnd2, true);
                        // positionate the text cursor inside the changed word to allow to cycle
                        if ( SwWrtShell *pWrtShell = dynamic_cast<SwWrtShell*>(
                                m_rDoc.getIDocumentLayoutAccess().GetCurrentViewShell()) )
                        {
                            pWrtShell->GetCursor()->GetPoint()->
                                    Assign(*aPos2.GetContentNode(), aPos2.GetContentIndex() - 1);
                        }
                    }
                }
            }
            return;
        }
    }