[Libreoffice-commits] core.git: Branch 'private/mst/sw_redlinehide_4a' - 27 commits - sw/inc sw/qa sw/source sw/uiconfig

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Nov 29 09:54:31 UTC 2018


Rebased ref, commits from common ancestor:
commit 39ed5f73a7bc5fc9cde880a8d7f569036fdb6fbc
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 18:15:41 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Nov 29 10:53:13 2018 +0100

    sw_redlinehide_4a: stop toggling ShowDelete in SwAutoFormat
    
    Change-Id: Ib6495d4248faa679d5a55642ac51baf419708287

diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 5f73e89f86e0..5dde2f1d9f1a 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -19,6 +19,10 @@
 
 #include <hintids.hxx>
 
+#include <officecfg/Office/Common.hxx>
+
+#include <comphelper/processfactory.hxx>
+
 #include <unotools/charclass.hxx>
 
 #include <editeng/boxitem.hxx>
@@ -2237,14 +2241,21 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, SvxSwAutoFormatFlags const &
                          m_nEndNdIdx = m_aEndNdIdx.GetIndex(),
                          m_pDoc->GetDocShell() );
 
+    uno::Reference<uno::XComponentContext> const xContext(
+            comphelper::getProcessComponentContext());
+    bool const isExp(officecfg::Office::Common::Misc::ExperimentalMode::get(xContext));
     RedlineFlags eRedlMode = m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags(), eOldMode = eRedlMode;
     if( m_aFlags.bWithRedlining )
     {
         m_pDoc->SetAutoFormatRedline( true );
-        eRedlMode = RedlineFlags::On | RedlineFlags::ShowInsert;
+        eRedlMode = isExp
+            ? RedlineFlags::On | (eOldMode & RedlineFlags::ShowMask)
+            : RedlineFlags::On | RedlineFlags::ShowInsert;
     }
     else
-      eRedlMode = RedlineFlags::ShowInsert | RedlineFlags::Ignore;
+      eRedlMode = isExp
+          ? RedlineFlags::Ignore | (eOldMode & RedlineFlags::ShowMask)
+          : RedlineFlags::ShowInsert | RedlineFlags::Ignore;
     m_pDoc->getIDocumentRedlineAccess().SetRedlineFlags( eRedlMode );
 
     // save undo state (might be turned off)
commit 09e94cb287e5c9ef24c497cf9479c53e24c55a9a
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 18:15:18 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Nov 29 10:53:13 2018 +0100

    currently we still have ShowDelete disableable
    
    Change-Id: I2f7bdee1d527895b745c7cf010e195e721556bd7

diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index bbd47e137d9f..5f73e89f86e0 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -1110,6 +1110,10 @@ bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges,
     bool isNoRedline(true);
     SwRedlineTable::size_type tmp;
     IDocumentRedlineAccess const& rIDRA(rDoc.getIDocumentRedlineAccess());
+    if (!(rIDRA.GetRedlineFlags() & RedlineFlags::ShowDelete))
+    {
+        return isNoRedline;
+    }
     rIDRA.GetRedline(*rDelPam.Start(), &tmp);
     SwPosition const* pCurrent(rDelPam.Start());
     for ( ; tmp < rIDRA.GetRedlineTable().size(); ++tmp)
commit b3b9d39775a5463627db850d1ba396d542381ecf
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 17:41:09 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Nov 29 10:53:13 2018 +0100

    sw_redlinehide_4a: TextFrameIndex goes live
    
    Change-Id: Ie59c09bdc57505e16022c43791d5e65cc233d5b9

diff --git a/sw/source/core/inc/TextFrameIndex.hxx b/sw/source/core/inc/TextFrameIndex.hxx
index d15fc7bf6691..3987bd5903fe 100644
--- a/sw/source/core/inc/TextFrameIndex.hxx
+++ b/sw/source/core/inc/TextFrameIndex.hxx
@@ -13,17 +13,13 @@
 #include <sal/types.h>
 #include <o3tl/strong_int.hxx>
 
-#if 0
-typedef o3tl::strong_int<sal_Int32, struct Tag_TextFrameIndex> TextFrameIndex;
-#else
 /**
  * Denotes a character index in a text frame at a layout level, after extent
  * mapping from a text node at a document model level.
  *
  * @see SwTextFrame::MapViewToModelPos().
  */
-typedef sal_Int32 TextFrameIndex;
-#endif
+typedef o3tl::strong_int<sal_Int32, struct Tag_TextFrameIndex> TextFrameIndex;
 
 #endif // INCLUDED_SW_SOURCE_CORE_INC_TEXTFRAMEINDEX_HXX
 
commit 891e78216169ee39502d6805ea1f5a576f942298
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 17:39:44 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Nov 29 10:53:13 2018 +0100

    sw_redlinehide_4a: fix up some more TextFrameIndex in tests
    
    Change-Id: I2232498b66f3d165deb6bf761879dd8ca16913c4

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index fb399694ed9d..fa698b44450d 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -4178,7 +4178,7 @@ void SwUiWriterTest::testTdf87922()
     SwNodeIndex aNodeIndex(pDoc->GetNodes().GetEndOfContent(), -1);
     const OUString& rText = aNodeIndex.GetNode().GetTextNode()->GetText();
     sal_Int32 nLength = rText.getLength();
-    SwDrawTextInfo aDrawTextInfo(pWrtShell, *pWrtShell->GetOut(), pScriptInfo, rText, 0, nLength);
+    SwDrawTextInfo aDrawTextInfo(pWrtShell, *pWrtShell->GetOut(), pScriptInfo, rText, TextFrameIndex(0), TextFrameIndex(nLength));
     // Root -> page -> body -> text.
     SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower());
     aDrawTextInfo.SetFrame(pTextFrame);
@@ -4222,17 +4222,17 @@ class PortionHandler : public SwPortionHandler
         mPortionItems.clear();
     }
 
-    virtual void Text(sal_Int32 nLength, sal_uInt16 nType,
+    virtual void Text(TextFrameIndex nLength, sal_uInt16 nType,
                       sal_Int32 /*nHeight*/, sal_Int32 /*nWidth*/) override
     {
-        mPortionItems.emplace_back("text", nLength, nType);
+        mPortionItems.emplace_back("text", sal_Int32(nLength), nType);
     }
 
-    virtual void Special(sal_Int32 nLength, const OUString & /*rText*/,
+    virtual void Special(TextFrameIndex nLength, const OUString & /*rText*/,
                          sal_uInt16 nType, sal_Int32 /*nHeight*/,
                          sal_Int32 /*nWidth*/, const SwFont* /*pFont*/) override
     {
-        mPortionItems.emplace_back("special", nLength, nType);
+        mPortionItems.emplace_back("special", sal_Int32(nLength), nType);
     }
 
     virtual void LineBreak(sal_Int32 /*nWidth*/) override
@@ -4240,9 +4240,9 @@ class PortionHandler : public SwPortionHandler
         mPortionItems.emplace_back("line_break", 0, 0);
     }
 
-    virtual void Skip(sal_Int32 nLength) override
+    virtual void Skip(TextFrameIndex nLength) override
     {
-        mPortionItems.emplace_back("skip", nLength, 0);
+        mPortionItems.emplace_back("skip", sal_Int32(nLength), 0);
     }
 
     virtual void Finish() override
commit 874255038aad25375a635ef7ba4c2430e6e5439e
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 17:27:39 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Nov 29 10:53:13 2018 +0100

    more of this in SwEditShell
    
    Change-Id: Ib644d0373963119b9f7fe6767b028fd89724feb3

diff --git a/sw/source/core/edit/edws.cxx b/sw/source/core/edit/edws.cxx
index 32770a346284..1b2e720d1821 100644
--- a/sw/source/core/edit/edws.cxx
+++ b/sw/source/core/edit/edws.cxx
@@ -30,6 +30,7 @@
 #include <acorrect.hxx>
 #include <swtable.hxx>
 #include <ndtxt.hxx>
+#include <txtfrm.hxx>
 #include <swundo.hxx>
 #include <SwRewriter.hxx>
 
@@ -265,9 +266,11 @@ void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, bool bInsert,
 
     SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCursor, cChar );
     // FIXME: this _must_ be called with reference to the actual node text!
-    OUString const& rNodeText(pTNd->GetText());
+    SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(GetLayout())));
+    TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
+    OUString const& rMergedText(pFrame->GetText());
     rACorr.DoAutoCorrect( aSwAutoCorrDoc,
-                    rNodeText, pCursor->GetPoint()->nContent.GetIndex(),
+                    rMergedText, sal_Int32(nPos),
                     cChar, bInsert, m_bNbspRunNext, GetWin() );
     if( cChar )
         SaveTableBoxContent( pCursor->GetPoint() );
@@ -285,13 +288,14 @@ bool SwEditShell::GetPrevAutoCorrWord( SvxAutoCorrect const & rACorr, OUString&
 
     bool bRet;
     SwPaM* pCursor = getShellCursor( true );
-    const sal_Int32 nPos = pCursor->GetPoint()->nContent.GetIndex();
     SwTextNode* pTNd = pCursor->GetNode().GetTextNode();
-    if( pTNd && nPos )
+    if (pTNd)
     {
         SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCursor, 0 );
+        SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(GetLayout())));
+        TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
         bRet = rACorr.GetPrevAutoCorrWord( aSwAutoCorrDoc,
-                                            pTNd->GetText(), nPos, rWord );
+                    pFrame->GetText(), sal_Int32(nPos), rWord );
     }
     else
         bRet = false;
commit 1a82fee82935a988a0f6a5757532d7f82b6ae685
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 17:09:22 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Nov 29 10:53:13 2018 +0100

    sw_redlinehide_4a: SwAutoFormat::AutoCorrect()
    
    Change-Id: I0ab7665f8635d6716fce996408db1e2bedf54d0c

diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 9edcce7ebc3b..bbd47e137d9f 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -187,7 +187,7 @@ class SwAutoFormat
     /// join with the previous paragraph
     void JoinPrevPara();
     /// execute AutoCorrect on current TextNode
-    void AutoCorrect( sal_Int32 nSttPos = 0 );
+    void AutoCorrect(TextFrameIndex nSttPos = TextFrameIndex(0));
 
     bool CanJoin(const SwTextFrame * pNextFrame) const
     {
@@ -1466,7 +1466,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
     DeleteLeadingTrailingBlanks();
 
     bool bChgBullet = false, bChgEnum = false;
-    sal_Int32 nAutoCorrPos = 0;
+    TextFrameIndex nAutoCorrPos(0);
 
     // if numbering is set, get the current one
     SwNumRule aRule( m_pDoc->GetUniqueNumRuleName(),
@@ -1719,7 +1719,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
                                   RES_CHRATR_FONT ) );
                 m_pDoc->SetFormatItemByAutoFormat( m_aDelPam, aSet );
                 m_aDelPam.DeleteMark();
-                nAutoCorrPos = 2;
+                nAutoCorrPos = TextFrameIndex(2);
                 aSet.ClearItem();
             }
             SvxTabStopItem aTStops( RES_PARATR_TABSTOP );
@@ -1877,7 +1877,7 @@ void SwAutoFormat::BuildHeadLine( sal_uInt16 nLvl )
 }
 
 /// Start autocorrection for the current TextNode
-void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
+void SwAutoFormat::AutoCorrect(TextFrameIndex nPos)
 {
     SvxAutoCorrect* pATst = SvxAutoCorrCfg::Get().GetAutoCorrect();
     ACFlags aSvxFlags = pATst->GetFlags( );
@@ -1892,8 +1892,8 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
         !m_aFlags.bChgWeightUnderl && !m_aFlags.bAddNonBrkSpace) )
         return;
 
-    const OUString* pText = &m_pCurTextNd->GetText();
-    if (nPos >= pText->getLength())
+    const OUString* pText = &m_pCurTextFrame->GetText();
+    if (TextFrameIndex(pText->getLength()) <= nPos)
         return;
 
     bool bGetLanguage = m_aFlags.bChgOrdinalNumber ||
@@ -1902,14 +1902,13 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
                         m_aFlags.bAddNonBrkSpace;
 
     m_aDelPam.DeleteMark();
-    m_aDelPam.GetPoint()->nNode = m_aNdIdx;
-    m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, 0 );
+    *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
 
     SwAutoCorrDoc aACorrDoc( *m_pEditShell, m_aDelPam );
 
     SwTextFrameInfo aFInfo( nullptr );
 
-    sal_Int32 nSttPos, nLastBlank = nPos;
+    TextFrameIndex nSttPos, nLastBlank = nPos;
     bool bFirst = m_aFlags.bCapitalStartSentence, bFirstSent = bFirst;
     sal_Unicode cChar = 0;
     bool bNbspRunNext = false;
@@ -1917,14 +1916,15 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
     CharClass& rAppCC = GetAppCharClass();
 
     do {
-        while (nPos < pText->getLength() && IsSpace(cChar = (*pText)[nPos]))
+        while (nPos < TextFrameIndex(pText->getLength())
+                && IsSpace(cChar = (*pText)[sal_Int32(nPos)]))
             ++nPos;
-        if (nPos == pText->getLength())
+        if (nPos == TextFrameIndex(pText->getLength()))
             break;      // that's it
 
         if( ( ( bReplaceQuote && '\"' == cChar ) ||
               ( bReplaceSglQuote && '\'' == cChar ) ) &&
-            (!nPos || ' ' == (*pText)[nPos-1]))
+            (!nPos || ' ' == (*pText)[sal_Int32(nPos)-1]))
         {
 
             // note: special case symbol fonts !!!
@@ -1933,14 +1933,14 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
             if( !aFInfo.IsBullet( nPos ))
             {
                 SetRedlineText( STR_AUTOFMTREDL_TYPO );
-                m_aDelPam.GetPoint()->nContent = nPos;
+                *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
                 bool bSetHardBlank = false;
 
                 OUString sReplace( pATst->GetQuote( aACorrDoc,
-                                    nPos, cChar, true ));
+                                    sal_Int32(nPos), cChar, true ));
 
                 m_aDelPam.SetMark();
-                m_aDelPam.GetPoint()->nContent = nPos+1;
+                m_aDelPam.GetPoint()->nContent = m_aDelPam.GetMark()->nContent.GetIndex() + 1;
                 if( 2 == sReplace.getLength() && ' ' == sReplace[ 1 ])
                 {
                     sReplace = sReplace.copy( 0, 1 );
@@ -1952,12 +1952,13 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
                 {
                     m_aNdIdx = m_aDelPam.GetPoint()->nNode;
                     m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
-                    pText = &m_pCurTextNd->GetText();
+                    m_pCurTextFrame = GetFrame( *m_pCurTextNd );
+                    pText = &m_pCurTextFrame->GetText();
                     m_aDelPam.SetMark();
                     aFInfo.SetFrame( nullptr );
                 }
 
-                nPos += sReplace.getLength() - 1;
+                nPos += TextFrameIndex(sReplace.getLength() - 1);
                 m_aDelPam.DeleteMark();
                 if( bSetHardBlank )
                 {
@@ -1969,10 +1970,10 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
 
         bool bCallACorr = false;
         int bBreak = 0;
-        if (nPos && IsSpace((*pText)[nPos-1]))
+        if (nPos && IsSpace((*pText)[sal_Int32(nPos) - 1]))
             nLastBlank = nPos;
-        for (nSttPos = nPos; !bBreak && nPos < pText->getLength(); ++nPos)
-            switch (cChar = (*pText)[nPos])
+        for (nSttPos = nPos; !bBreak && nPos < TextFrameIndex(pText->getLength()); ++nPos)
+            switch (cChar = (*pText)[sal_Int32(nPos)])
             {
             case '\"':
             case '\'':
@@ -1985,9 +1986,9 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
                     {
                         SetRedlineText( STR_AUTOFMTREDL_TYPO );
                         bool bSetHardBlank = false;
-                        m_aDelPam.GetPoint()->nContent = nPos;
+                        *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
                         OUString sReplace( pATst->GetQuote( aACorrDoc,
-                                                    nPos, cChar, false ));
+                                            sal_Int32(nPos), cChar, false) );
 
                         if( 2 == sReplace.getLength() && ' ' == sReplace[ 0 ])
                         {
@@ -1996,27 +1997,29 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
                         }
 
                         m_aDelPam.SetMark();
-                        m_aDelPam.GetPoint()->nContent = nPos+1;
+                        m_aDelPam.GetPoint()->nContent = m_aDelPam.GetMark()->nContent.GetIndex() + 1;
                         m_pDoc->getIDocumentContentOperations().ReplaceRange( m_aDelPam, sReplace, false );
 
                         if( m_aFlags.bWithRedlining )
                         {
                             m_aNdIdx = m_aDelPam.GetPoint()->nNode;
                             m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
-                            pText = &m_pCurTextNd->GetText();
+                            m_pCurTextFrame = GetFrame( *m_pCurTextNd );
+                            pText = &m_pCurTextFrame->GetText();
                             m_aDelPam.SetMark();
                             m_aDelPam.DeleteMark();
                             aFInfo.SetFrame( nullptr );
                         }
 
-                        nPos += sReplace.getLength() - 1;
+                        nPos += TextFrameIndex(sReplace.getLength() - 1);
                         m_aDelPam.DeleteMark();
 
                         if( bSetHardBlank )
                         {
-                            m_aDelPam.GetPoint()->nContent = nPos;
+                            *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
                             m_pDoc->getIDocumentContentOperations().InsertString( m_aDelPam, OUString(CHAR_HARDBLANK) );
-                            m_aDelPam.GetPoint()->nContent = ++nPos;
+                            ++nPos;
+                            *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
                         }
                     }
                 }
@@ -2034,25 +2037,26 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
                                             ? STR_AUTOFMTREDL_BOLD
                                             : STR_AUTOFMTREDL_UNDER );
 
-                        sal_Unicode cBlank = nSttPos ? (*pText)[nSttPos - 1] : 0;
-                        m_aDelPam.GetPoint()->nContent = nPos;
+                        sal_Unicode cBlank = nSttPos ? (*pText)[sal_Int32(nSttPos) - 1] : 0;
+                        *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
 
-                        if( pATst->FnChgWeightUnderl( aACorrDoc, *pText, nPos ))
+                        if (pATst->FnChgWeightUnderl(aACorrDoc, *pText, sal_Int32(nPos)))
                         {
                             if( m_aFlags.bWithRedlining )
                             {
                                 m_aNdIdx = m_aDelPam.GetPoint()->nNode;
                                 m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
-                                pText = &m_pCurTextNd->GetText();
+                                m_pCurTextFrame = GetFrame( *m_pCurTextNd );
+                                pText = &m_pCurTextFrame->GetText();
                                 m_aDelPam.SetMark();
                                 m_aDelPam.DeleteMark();
                                 aFInfo.SetFrame( nullptr );
                             }
                             //#125102# in case of the mode RedlineFlags::ShowDelete the ** are still contained in pText
                             if(!(m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags() & RedlineFlags::ShowDelete))
-                                nPos = m_aDelPam.GetPoint()->nContent.GetIndex() - 1;
+                                nPos = m_pCurTextFrame->MapModelToViewPos(*m_aDelPam.GetPoint()) - TextFrameIndex(1);
                             // Was a character deleted before starting?
-                            if (cBlank && cBlank != (*pText)[nSttPos - 1])
+                            if (cBlank && cBlank != (*pText)[sal_Int32(nSttPos) - 1])
                                 --nSttPos;
                         }
                     }
@@ -2062,11 +2066,11 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
                 if ( m_aFlags.bAddNonBrkSpace )
                 {
                     LanguageType eLang = bGetLanguage
-                                           ? m_pCurTextNd->GetLang( nSttPos )
-                                           : LANGUAGE_SYSTEM;
+                        ? m_pCurTextFrame->GetLangOfChar(nSttPos, 0, true)
+                        : LANGUAGE_SYSTEM;
 
                     SetRedlineText( STR_AUTOFMTREDL_NON_BREAK_SPACE );
-                    if ( pATst->FnAddNonBrkSpace( aACorrDoc, *pText, nPos, eLang, bNbspRunNext ) )
+                    if (pATst->FnAddNonBrkSpace(aACorrDoc, *pText, sal_Int32(nPos), eLang, bNbspRunNext))
                         --nPos;
                 }
                 break;
@@ -2078,7 +2082,7 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
                     bFirstSent = true;
                 SAL_FALLTHROUGH;
             default:
-                if( !( rAppCC.isLetterNumeric( *pText, nPos )
+                if (!(rAppCC.isLetterNumeric(*pText, sal_Int32(nPos))
                         || '/' == cChar )) //  '/' should not be a word separator (e.g. '1/2' needs to be handled as one word for replacement)
                 {
                     --nPos;     // revert ++nPos which was decremented in for loop
@@ -2089,7 +2093,7 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
 
         if( nPos == nSttPos )
         {
-            if (++nPos == pText->getLength())
+            if (++nPos == TextFrameIndex(pText->getLength()))
                 bCallACorr = true;
         }
         else
@@ -2097,18 +2101,19 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
 
         if( bCallACorr )
         {
-            m_aDelPam.GetPoint()->nContent = nPos;
+            *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
             SetRedlineText( STR_AUTOFMTREDL_USE_REPLACE );
             if( m_aFlags.bAutoCorrect &&
-                aACorrDoc.ChgAutoCorrWord( nSttPos, nPos, *pATst, nullptr ) )
+                aACorrDoc.ChgAutoCorrWord(reinterpret_cast<sal_Int32&>(nSttPos), sal_Int32(nPos), *pATst, nullptr))
             {
-                nPos = m_aDelPam.GetPoint()->nContent.GetIndex();
+                nPos = m_pCurTextFrame->MapModelToViewPos(*m_aDelPam.GetPoint()) - TextFrameIndex(1);
 
                 if( m_aFlags.bWithRedlining )
                 {
                     m_aNdIdx = m_aDelPam.GetPoint()->nNode;
                     m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
-                    pText = &m_pCurTextNd->GetText();
+                    m_pCurTextFrame = GetFrame( *m_pCurTextNd );
+                    pText = &m_pCurTextFrame->GetText();
                     m_aDelPam.SetMark();
                     m_aDelPam.DeleteMark();
                 }
@@ -2117,39 +2122,41 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
             }
 
             LanguageType eLang = bGetLanguage
-                                           ? m_pCurTextNd->GetLang( nSttPos )
-                                           : LANGUAGE_SYSTEM;
+                    ? m_pCurTextFrame->GetLangOfChar(nSttPos, 0, true)
+                    : LANGUAGE_SYSTEM;
 
             if ( m_aFlags.bAddNonBrkSpace )
             {
                 SetRedlineText( STR_AUTOFMTREDL_NON_BREAK_SPACE );
-                pATst->FnAddNonBrkSpace( aACorrDoc, *pText, nPos, eLang, bNbspRunNext );
+                pATst->FnAddNonBrkSpace(aACorrDoc, *pText, sal_Int32(nPos), eLang, bNbspRunNext);
             }
 
             if( ( m_aFlags.bChgOrdinalNumber &&
                     SetRedlineText( STR_AUTOFMTREDL_ORDINAL ) &&
-                    pATst->FnChgOrdinalNumber( aACorrDoc, *pText, nSttPos, nPos, eLang ) ) ||
+                    pATst->FnChgOrdinalNumber(aACorrDoc, *pText, sal_Int32(nSttPos), sal_Int32(nPos), eLang)) ||
                 ( m_aFlags.bChgToEnEmDash &&
                     SetRedlineText( STR_AUTOFMTREDL_DASH ) &&
-                    pATst->FnChgToEnEmDash( aACorrDoc, *pText, nSttPos, nPos, eLang ) ) ||
+                    pATst->FnChgToEnEmDash(aACorrDoc, *pText, sal_Int32(nSttPos), sal_Int32(nPos), eLang)) ||
                 ( m_aFlags.bSetINetAttr &&
-                    (nPos == pText->getLength() || IsSpace((*pText)[nPos])) &&
+                    (nPos == TextFrameIndex(pText->getLength()) || IsSpace((*pText)[sal_Int32(nPos)])) &&
                     SetRedlineText( STR_AUTOFMTREDL_DETECT_URL ) &&
-                    pATst->FnSetINetAttr( aACorrDoc, *pText, nLastBlank, nPos, eLang ) ) )
-                    nPos = m_aDelPam.GetPoint()->nContent.GetIndex();
+                    pATst->FnSetINetAttr(aACorrDoc, *pText, sal_Int32(nLastBlank), sal_Int32(nPos), eLang)))
+            {
+                nPos = m_pCurTextFrame->MapModelToViewPos(*m_aDelPam.GetPoint()) - TextFrameIndex(1);
+            }
             else
             {
                 // two capital letters at the beginning of a word?
                 if( m_aFlags.bCapitalStartWord )
                 {
                     SetRedlineText( STR_AUTOFMTREDL_CPTL_STT_WORD );
-                    pATst->FnCapitalStartWord( aACorrDoc, *pText, nSttPos, nPos, eLang );
+                    pATst->FnCapitalStartWord(aACorrDoc, *pText, sal_Int32(nSttPos), sal_Int32(nPos), eLang);
                 }
                 // capital letter at the beginning of a sentence?
                 if( m_aFlags.bCapitalStartSentence && bFirst )
                 {
                     SetRedlineText( STR_AUTOFMTREDL_CPTL_STT_SENT );
-                    pATst->FnCapitalStartSentence( aACorrDoc, *pText, true, nSttPos, nPos, eLang);
+                    pATst->FnCapitalStartSentence(aACorrDoc, *pText, true, sal_Int32(nSttPos), sal_Int32(nPos), eLang);
                 }
 
                 bFirst = bFirstSent;
@@ -2159,13 +2166,15 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
                 {
                     m_aNdIdx = m_aDelPam.GetPoint()->nNode;
                     m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
-                    pText = &m_pCurTextNd->GetText();
+                    m_pCurTextFrame = GetFrame( *m_pCurTextNd );
+                    pText = &m_pCurTextFrame->GetText();
                     m_aDelPam.SetMark();
                     m_aDelPam.DeleteMark();
                 }
             }
         }
-    } while (nPos < pText->getLength());
+    }
+    while (nPos < TextFrameIndex(pText->getLength()));
     ClearRedlineText();
 }
 
commit 0350a3f9b830e9f6f529ab499bd6ae44c09fd109
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 15:51:02 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Nov 29 10:53:13 2018 +0100

    sw_redlinehide_4a: SwAutoCorrDoc iterates frames, not nodes
    
    Adapt this in a similar way, with a DeleteSel() that skips over
    delete redlines.
    
    The Replace functions fortunately only have callers that replace 1
    character currently, but there is another ReplaceRange() call that
    needs a litte more complicated handling.
    
    Change-Id: Idd5c80e96c0f355d3dc965b2f70376258d23e1a3

diff --git a/sw/source/core/edit/acorrect.cxx b/sw/source/core/edit/acorrect.cxx
index a78c94942ec8..e5ca4d63c69b 100644
--- a/sw/source/core/edit/acorrect.cxx
+++ b/sw/source/core/edit/acorrect.cxx
@@ -27,6 +27,8 @@
 #include <editsh.hxx>
 #include <doc.hxx>
 #include <pam.hxx>
+#include <unocrsr.hxx>
+#include <txtfrm.hxx>
 #include <ndtxt.hxx>
 #include <acorrect.hxx>
 #include <shellio.hxx>
@@ -100,12 +102,32 @@ SwAutoCorrDoc::~SwAutoCorrDoc()
 
 void SwAutoCorrDoc::DeleteSel( SwPaM& rDelPam )
 {
+    // this should work with plain SwPaM as well because start and end
+    // are always in same node, but since there is GetRanges already...
+    std::vector<std::shared_ptr<SwUnoCursor>> ranges;
+    if (sw::GetRanges(ranges, *rEditSh.GetDoc(), rDelPam))
+    {
+        DeleteSelImpl(rDelPam);
+    }
+    else
+    {
+        for (auto const& pCursor : ranges)
+        {
+            DeleteSelImpl(*pCursor);
+        }
+    }
+}
+
+void SwAutoCorrDoc::DeleteSelImpl(SwPaM & rDelPam)
+{
     SwDoc* pDoc = rEditSh.GetDoc();
     if( pDoc->IsAutoFormatRedline() )
     {
         // so that also the DelPam be moved,  include it in the
         // Shell-Cursr-Ring !!
-        PaMIntoCursorShellRing aTmp( rEditSh, rCursor, rDelPam );
+        // ??? is that really necessary - this should never join nodes, so Update should be enough?
+//        PaMIntoCursorShellRing aTmp( rEditSh, rCursor, rDelPam );
+        assert(rDelPam.GetPoint()->nNode == rDelPam.GetMark()->nNode);
         pDoc->getIDocumentContentOperations().DeleteAndJoin( rDelPam );
     }
     else
@@ -116,8 +138,12 @@ void SwAutoCorrDoc::DeleteSel( SwPaM& rDelPam )
 
 bool SwAutoCorrDoc::Delete( sal_Int32 nStt, sal_Int32 nEnd )
 {
-    const SwNodeIndex& rNd = rCursor.GetPoint()->nNode;
-    SwPaM aSel( rNd, nStt, rNd, nEnd );
+    SwTextNode const*const pTextNd = rCursor.GetNode().GetTextNode();
+    SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+                pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+    assert(pFrame);
+    SwPaM aSel(pFrame->MapViewToModelPos(TextFrameIndex(nStt)),
+               pFrame->MapViewToModelPos(TextFrameIndex(nEnd)));
     DeleteSel( aSel );
 
     if( bUndoIdInitialized )
@@ -127,7 +153,11 @@ bool SwAutoCorrDoc::Delete( sal_Int32 nStt, sal_Int32 nEnd )
 
 bool SwAutoCorrDoc::Insert( sal_Int32 nPos, const OUString& rText )
 {
-    SwPaM aPam( rCursor.GetPoint()->nNode.GetNode(), nPos );
+    SwTextNode const*const pTextNd = rCursor.GetNode().GetTextNode();
+    SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+                pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+    assert(pFrame);
+    SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(nPos)));
     rEditSh.GetDoc()->getIDocumentContentOperations().InsertString( aPam, rText );
     if( !bUndoIdInitialized )
     {
@@ -148,28 +178,43 @@ bool SwAutoCorrDoc::Replace( sal_Int32 nPos, const OUString& rText )
 
 bool SwAutoCorrDoc::ReplaceRange( sal_Int32 nPos, sal_Int32 nSourceLength, const OUString& rText )
 {
-    SwPaM* pPam = &rCursor;
-    if( pPam->GetPoint()->nContent.GetIndex() != nPos )
+    assert(nSourceLength == 1); // sw_redlinehide: this is currently the case,
+    // and ensures that the replace range cannot *contain* delete redlines,
+    // so we don't need something along the lines of:
+    //    if (sw::GetRanges(ranges, *rEditSh.GetDoc(), aPam))
+    //        ReplaceImpl(...)
+    //    else
+    //        ReplaceImpl(ranges.begin())
+    //        for (ranges.begin() + 1; ranges.end(); )
+    //            DeleteImpl(*it)
+
+    SwTextNode * const pNd = rCursor.GetNode().GetTextNode();
+    if ( !pNd )
     {
-        pPam = new SwPaM( *rCursor.GetPoint() );
-        pPam->GetPoint()->nContent = nPos;
+        return false;
     }
 
-    SwTextNode * const pNd = pPam->GetNode().GetTextNode();
-    if ( !pNd )
+    SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+                pNd->getLayoutFrame(rEditSh.GetLayout())));
+    assert(pFrame);
+    std::pair<SwTextNode *, sal_Int32> const pos(pFrame->MapViewToModel(TextFrameIndex(nPos)));
+
+    SwPaM* pPam = &rCursor;
+    if (pPam->GetPoint()->nNode != *pos.first
+        || pPam->GetPoint()->nContent != pos.second)
     {
-        return false;
+        pPam = new SwPaM(*pos.first, pos.second);
     }
 
     // text attributes with dummy characters must not be replaced!
     bool bDoReplace = true;
     sal_Int32 const nLen = rText.getLength();
-    for ( sal_Int32 n = 0; n < nLen && n + nPos < pNd->GetText().getLength(); ++n )
+    for (sal_Int32 n = 0; n < nLen && n + nPos < pFrame->GetText().getLength(); ++n)
     {
-        sal_Unicode const Char = pNd->GetText()[n + nPos];
-        if ( ( CH_TXTATR_BREAKWORD == Char || CH_TXTATR_INWORD == Char )
-             && pNd->GetTextAttrForCharAt( n + nPos ) )
+        sal_Unicode const Char = pFrame->GetText()[n + nPos];
+        if (CH_TXTATR_BREAKWORD == Char || CH_TXTATR_INWORD == Char)
         {
+            assert(pFrame->MapViewToModel(TextFrameIndex(n+nPos)).first->GetTextAttrForCharAt(pFrame->MapViewToModel(TextFrameIndex(n+nPos)).second));
             bDoReplace = false;
             break;
         }
@@ -181,17 +226,18 @@ bool SwAutoCorrDoc::ReplaceRange( sal_Int32 nPos, sal_Int32 nSourceLength, const
 
         if( pDoc->IsAutoFormatRedline() )
         {
-            if (nPos == pNd->GetText().getLength()) // at the End do an Insert
+            if (nPos == pFrame->GetText().getLength()) // at the End do an Insert
             {
                 pDoc->getIDocumentContentOperations().InsertString( *pPam, rText );
             }
             else
             {
+                assert(pos.second != pos.first->Len()); // must be _before_ char
                 PaMIntoCursorShellRing aTmp( rEditSh, rCursor, *pPam );
 
                 pPam->SetMark();
                 pPam->GetPoint()->nContent = std::min<sal_Int32>(
-                        pNd->GetText().getLength(), nPos + nSourceLength);
+                    pos.first->GetText().getLength(), pos.second + nSourceLength);
                 pDoc->getIDocumentContentOperations().ReplaceRange( *pPam, rText, false );
                 pPam->Exchange();
                 pPam->DeleteMark();
@@ -203,7 +249,7 @@ bool SwAutoCorrDoc::ReplaceRange( sal_Int32 nPos, sal_Int32 nSourceLength, const
             {
                 pPam->SetMark();
                 pPam->GetPoint()->nContent = std::min<sal_Int32>(
-                        pNd->GetText().getLength(), nPos + nSourceLength);
+                    pos.first->GetText().getLength(), pos.second + nSourceLength);
                 pDoc->getIDocumentContentOperations().ReplaceRange( *pPam, rText, false );
                 pPam->Exchange();
                 pPam->DeleteMark();
@@ -232,8 +278,12 @@ bool SwAutoCorrDoc::ReplaceRange( sal_Int32 nPos, sal_Int32 nSourceLength, const
 void SwAutoCorrDoc::SetAttr( sal_Int32 nStt, sal_Int32 nEnd, sal_uInt16 nSlotId,
                                         SfxPoolItem& rItem )
 {
-    const SwNodeIndex& rNd = rCursor.GetPoint()->nNode;
-    SwPaM aPam( rNd, nStt, rNd, nEnd );
+    SwTextNode const*const pTextNd = rCursor.GetNode().GetTextNode();
+    SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+                pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+    assert(pFrame);
+    SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(nStt)),
+               pFrame->MapViewToModelPos(TextFrameIndex(nEnd)));
 
     SfxItemPool& rPool = rEditSh.GetDoc()->GetAttrPool();
     sal_uInt16 nWhich = rPool.GetWhich( nSlotId, false );
@@ -253,8 +303,12 @@ void SwAutoCorrDoc::SetAttr( sal_Int32 nStt, sal_Int32 nEnd, sal_uInt16 nSlotId,
 
 bool SwAutoCorrDoc::SetINetAttr( sal_Int32 nStt, sal_Int32 nEnd, const OUString& rURL )
 {
-    const SwNodeIndex& rNd = rCursor.GetPoint()->nNode;
-    SwPaM aPam( rNd, nStt, rNd, nEnd );
+    SwTextNode const*const pTextNd = rCursor.GetNode().GetTextNode();
+    SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+                pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+    assert(pFrame);
+    SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(nStt)),
+               pFrame->MapViewToModelPos(TextFrameIndex(nEnd)));
 
     SfxItemSet aSet( rEditSh.GetDoc()->GetAttrPool(),
                         svl::Items<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT>{} );
@@ -276,18 +330,25 @@ OUString const* SwAutoCorrDoc::GetPrevPara(bool const bAtNormalPos)
     OUString const* pStr(nullptr);
 
     if( bAtNormalPos || !pIdx )
-        pIdx.reset(new SwNodeIndex( rCursor.GetPoint()->nNode, -1 ));
-    else
-        --(*pIdx);
+    {
+        pIdx.reset(new SwNodeIndex(rCursor.GetPoint()->nNode));
+    }
+    sw::GotoPrevLayoutTextFrame(*pIdx, rEditSh.GetLayout());
 
-    SwTextNode* pTNd = pIdx->GetNode().GetTextNode();
-    while (pTNd && !pTNd->GetText().getLength())
+    SwTextFrame const* pFrame(nullptr);
+    for (SwTextNode * pTextNd = pIdx->GetNode().GetTextNode();
+             pTextNd; pTextNd = pIdx->GetNode().GetTextNode())
     {
-        --(*pIdx);
-        pTNd = pIdx->GetNode().GetTextNode();
+        pFrame = static_cast<SwTextFrame const*>(
+                pTextNd->getLayoutFrame(rEditSh.GetLayout()));
+        if (pFrame && !pFrame->GetText().isEmpty())
+        {
+            break;
+        }
+        sw::GotoPrevLayoutTextFrame(*pIdx, rEditSh.GetLayout());
     }
-    if( pTNd && 0 == pTNd->GetAttrOutlineLevel() )
-        pStr = & pTNd->GetText();
+    if (pFrame && 0 == pFrame->GetTextNodeForParaProps()->GetAttrOutlineLevel())
+        pStr = & pFrame->GetText();
 
     if( bUndoIdInitialized )
         bUndoIdInitialized = true;
@@ -316,20 +377,24 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
         eLang = GetAppLanguage();
     LanguageTag aLanguageTag( eLang);
 
+    SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+                pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+    assert(pFrame);
+
     //JP 22.04.99: Bug 63883 - Special treatment for dots.
-    bool bLastCharIsPoint = nEndPos < pTextNd->GetText().getLength() &&
-                            ('.' == pTextNd->GetText()[nEndPos]);
+    bool bLastCharIsPoint = nEndPos < pFrame->GetText().getLength() &&
+                            ('.' == pFrame->GetText()[nEndPos]);
 
     const SvxAutocorrWord* pFnd = rACorrect.SearchWordsInList(
-                                pTextNd->GetText(), rSttPos, nEndPos, *this, aLanguageTag );
+                pFrame->GetText(), rSttPos, nEndPos, *this, aLanguageTag);
     SwDoc* pDoc = rEditSh.GetDoc();
     if( pFnd )
     {
         // replace also last colon of keywords surrounded by colons (for example, ":name:")
         bool replaceLastChar = pFnd->GetShort()[0] == ':' && pFnd->GetShort().endsWith(":");
 
-        const SwNodeIndex& rNd = rCursor.GetPoint()->nNode;
-        SwPaM aPam( rNd, rSttPos, rNd, nEndPos + (replaceLastChar ? 1 : 0) );
+        SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(rSttPos)),
+                   pFrame->MapViewToModelPos(TextFrameIndex(nEndPos + (replaceLastChar ? 1 : 0))));
 
         if( pFnd->IsTextOnly() )
         {
@@ -338,7 +403,23 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
                 '.' != pFnd->GetLong()[ pFnd->GetLong().getLength() - 1 ] )
             {
                 // replace the selection
-                pDoc->getIDocumentContentOperations().ReplaceRange( aPam, pFnd->GetLong(), false);
+                std::vector<std::shared_ptr<SwUnoCursor>> ranges;
+                if (sw::GetRanges(ranges, *rEditSh.GetDoc(), aPam))
+                {
+                    pDoc->getIDocumentContentOperations().ReplaceRange(aPam, pFnd->GetLong(), false);
+                }
+                else
+                {
+                    assert(!ranges.empty());
+                    assert(ranges.front()->GetPoint()->nNode == ranges.front()->GetMark()->nNode);
+                    pDoc->getIDocumentContentOperations().ReplaceRange(
+                            *ranges.front(), pFnd->GetLong(), false);
+                    for (auto it = ranges.begin() + 1; it != ranges.end(); ++it)
+                    {
+                        DeleteSel(**it);
+                    }
+                }
+
                 // tdf#83260 After calling sw::DocumentContentOperationsManager::ReplaceRange
                 // pTextNd may become invalid when change tracking is on and Edit -> Track Changes -> Show == OFF.
                 // ReplaceRange shows changes, this moves deleted nodes from special section to document.
@@ -360,7 +441,8 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
                 if( pPara )
                 {
                     OSL_ENSURE( !pIdx, "who has not deleted his Index?" );
-                    pIdx.reset(new SwNodeIndex( rCursor.GetPoint()->nNode, -1 ));
+                    pIdx.reset(new SwNodeIndex( rCursor.GetPoint()->nNode ));
+                    sw::GotoPrevLayoutTextFrame(*pIdx, rEditSh.GetLayout());
                 }
 
                 SwDoc* pAutoDoc = aTBlks.GetDoc();
@@ -391,7 +473,7 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
 
                 if( pPara )
                 {
-                    ++(*pIdx);
+                    sw::GotoNextLayoutTextFrame(*pIdx, rEditSh.GetLayout());
                     pTextNd = pIdx->GetNode().GetTextNode();
                 }
                 bRet = true;
@@ -401,7 +483,11 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
     }
 
     if( bRet && pPara && pTextNd )
-        *pPara = pTextNd->GetText();
+    {
+        SwTextFrame const*const pNewFrame(static_cast<SwTextFrame const*>(
+                    pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+        *pPara = pNewFrame->GetText();
+    }
 
     return bRet;
 }
@@ -428,7 +514,12 @@ LanguageType SwAutoCorrDoc::GetLanguage( sal_Int32 nPos ) const
     SwTextNode* pNd = rCursor.GetPoint()->nNode.GetNode().GetTextNode();
 
     if( pNd )
-        eRet = pNd->GetLang( nPos );
+    {
+        SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+                    pNd->getLayoutFrame(rEditSh.GetLayout())));
+        assert(pFrame);
+        eRet = pFrame->GetLangOfChar(TextFrameIndex(nPos), 0, true);
+    }
     if(LANGUAGE_SYSTEM == eRet)
         eRet = GetAppLanguage();
     return eRet;
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 7d4143db42b3..9edcce7ebc3b 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -1102,6 +1102,8 @@ void SwAutoFormat::DeleteLeadingTrailingBlanks(bool bStart, bool bEnd)
     }
 }
 
+namespace sw {
+
 bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges,
         SwDoc & rDoc, SwPaM const& rDelPam)
 {
@@ -1136,6 +1138,8 @@ bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges,
     return isNoRedline;
 }
 
+} // namespace sw
+
 void SwAutoFormat::DeleteSel(SwPaM & rDelPam)
 {
     std::vector<std::shared_ptr<SwUnoCursor>> ranges; // need correcting cursor
diff --git a/sw/source/core/inc/acorrect.hxx b/sw/source/core/inc/acorrect.hxx
index f14edf751681..73f63c1ebac8 100644
--- a/sw/source/core/inc/acorrect.hxx
+++ b/sw/source/core/inc/acorrect.hxx
@@ -21,10 +21,14 @@
 #define INCLUDED_SW_SOURCE_CORE_INC_ACORRECT_HXX
 
 #include <memory>
+#include <vector>
+
 #include <tools/solar.h>
 #include <editeng/svxacorr.hxx>
 #include <swundo.hxx>
 
+class SwDoc;
+class SwUnoCursor;
 class SwEditShell;
 class SwPaM;
 class SwNodeIndex;
@@ -53,6 +57,7 @@ class SwAutoCorrDoc : public SvxAutoCorrDoc
     bool    bUndoIdInitialized;
 
     void DeleteSel( SwPaM& rDelPam );
+    void DeleteSelImpl(SwPaM & rDelPam);
 
 public:
     SwAutoCorrDoc( SwEditShell& rEditShell, SwPaM& rPam, sal_Unicode cIns = 0 );
@@ -111,6 +116,13 @@ public:
     bool CheckDelChar(const SwPosition& rPos);
 };
 
+namespace sw {
+
+bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges,
+        SwDoc & rDoc, SwPaM const& rDelPam);
+
+} // namespace sw
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 11a1fabfb00c0cb7d64b455474a8cb40a33e0387
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Nov 27 18:28:41 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Thu Nov 29 10:53:13 2018 +0100

    sw_redlinehide_4a: SwAutoFormat iterates frames, not nodes
    
    In order to not require moving the delete redlines out of the document
    body, rely on the DeleteSel() implementation skipping over the redlines,
    and also pass the shell's layout to the various SwDoc functions that
    are called.
    
    Previously, the redlines were not deleted by DeleteSel() due to
    SwAutoFormat setting RedlineFlags::Ignore.
    
    Change-Id: Ib05ecb534993368d81f66e70124617968b4c8e9a

diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 0b7d3a170ba1..253da644837f 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -1803,6 +1803,9 @@ void SwDoc::SetTextFormatCollByAutoFormat( const SwPosition& rPos, sal_uInt16 nP
     {
         aPam.SetMark();
         aPam.GetMark()->nContent.Assign(pTNd, pTNd->GetText().getLength());
+        // sw_redlinehide: don't need layout currently because the only caller
+        // passes in the properties node
+        assert(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(nullptr))->GetTextNodeForParaProps() == pTNd);
         getIDocumentContentOperations().InsertItemSet( aPam, *pSet );
     }
 }
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 6ff31e6094c8..7d4143db42b3 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -135,34 +135,37 @@ class SwAutoFormat
         { return (' ' == c || '\t' == c || 0x0a == c|| 0x3000 == c /* Jap. space */); }
 
     void SetColl( sal_uInt16 nId, bool bHdLineOrText = false );
-    OUString GoNextPara();
-    bool HasObjects( const SwNode& rNd );
+    void GoNextPara();
+    bool HasObjects(const SwTextFrame &);
 
     // TextNode methods
-    const SwTextNode* GetNextNode() const;
-    static bool IsEmptyLine( const SwTextNode& rNd )
-        {   return rNd.GetText().isEmpty() ||
-                rNd.GetText().getLength() == GetLeadingBlanks( rNd.GetText() ); }
-
-    bool IsOneLine( const SwTextNode& ) const;
-    bool IsFastFullLine( const SwTextNode& ) const;
-    bool IsNoAlphaLine( const SwTextNode&) const;
-    bool IsEnumericChar( const SwTextNode&) const;
-    static bool IsBlanksInString( const SwTextNode&);
-    sal_uInt16 CalcLevel( const SwTextNode&, sal_uInt16 *pDigitLvl = nullptr ) const;
-    sal_Int32 GetBigIndent( sal_Int32& rCurrentSpacePos ) const;
+    const SwTextFrame * GetNextNode(bool isCheckEnd = true) const;
+    static bool IsEmptyLine(const SwTextFrame & rFrame)
+    {
+        return rFrame.GetText().isEmpty()
+            || rFrame.GetText().getLength() == GetLeadingBlanks(rFrame.GetText());
+    }
+
+    bool IsOneLine(const SwTextFrame &) const;
+    bool IsFastFullLine(const SwTextFrame &) const;
+    bool IsNoAlphaLine(const SwTextFrame &) const;
+    bool IsEnumericChar(const SwTextFrame &) const;
+    static bool IsBlanksInString(const SwTextFrame&);
+    sal_uInt16 CalcLevel(const SwTextFrame&, sal_uInt16 *pDigitLvl = nullptr) const;
+    sal_Int32 GetBigIndent(TextFrameIndex & rCurrentSpacePos) const;
 
     static OUString DelLeadingBlanks(const OUString& rStr);
     static OUString DelTrailingBlanks( const OUString& rStr );
     static sal_Int32 GetLeadingBlanks( const OUString& rStr );
     static sal_Int32 GetTrailingBlanks( const OUString& rStr );
 
-    bool IsFirstCharCapital( const SwTextNode& rNd ) const;
-    sal_uInt16 GetDigitLevel( const SwTextNode& rTextNd, sal_Int32& rPos,
+    bool IsFirstCharCapital(const SwTextFrame & rNd) const;
+    sal_uInt16 GetDigitLevel(const SwTextFrame& rFrame, TextFrameIndex& rPos,
                             OUString* pPrefix = nullptr, OUString* pPostfix = nullptr,
                             OUString* pNumTypes = nullptr ) const;
     /// get the FORMATTED TextFrame
     SwTextFrame* GetFrame( const SwTextNode& rTextNd ) const;
+    SwTextFrame * EnsureFormatted(SwTextFrame const&) const;
 
     void BuildIndent();
     void BuildText();
@@ -171,11 +174,10 @@ class SwAutoFormat
     void BuildNegIndent( SwTwips nSpaces );
     void BuildHeadLine( sal_uInt16 nLvl );
 
-    static bool HasSelBlanks( SwPaM& rPam );
-    static bool HasBreakAttr( const SwTextNode& );
+    static bool HasBreakAttr(const SwTextFrame &);
     void DeleteSel( SwPaM& rPam );
     void DeleteSelImpl(SwPaM & rDelPam, SwPaM & rPamToCorrect);
-    bool DeleteJoinCurNextPara( const OUString& rNxtPara );
+    bool DeleteJoinCurNextPara(SwTextFrame const* pNextFrame, bool bIgnoreLeadingBlanks = false);
     /// delete in the node start and/or end
     void DeleteLeadingTrailingBlanks( bool bStart = true, bool bEnd = true );
     void DelEmptyLine( bool bTstNextPara = true );
@@ -187,19 +189,22 @@ class SwAutoFormat
     /// execute AutoCorrect on current TextNode
     void AutoCorrect( sal_Int32 nSttPos = 0 );
 
-    bool CanJoin( const SwTextNode* pTextNd ) const
+    bool CanJoin(const SwTextFrame * pNextFrame) const
     {
-        return !m_bEnd && pTextNd &&
-             !IsEmptyLine( *pTextNd ) &&
-             !IsNoAlphaLine( *pTextNd) &&
-             !IsEnumericChar( *pTextNd ) &&
-             ((COMPLETE_STRING - 50 - pTextNd->GetText().getLength()) >
-                    m_pCurTextNd->GetText().getLength()) &&
-             !HasBreakAttr( *pTextNd );
+        return !m_bEnd && pNextFrame
+            && !IsEmptyLine(*pNextFrame)
+            && !IsNoAlphaLine(*pNextFrame)
+            && !IsEnumericChar(*pNextFrame)
+            // check the last / first nodes here...
+            && ((COMPLETE_STRING - 50 - pNextFrame->GetTextNodeFirst()->GetText().getLength())
+                > (m_pCurTextFrame->GetMergedPara()
+                      ? m_pCurTextFrame->GetMergedPara()->pLastNode
+                      : m_pCurTextNd)->GetText().getLength())
+            && !HasBreakAttr(*pNextFrame);
     }
 
     /// is a dot at the end ??
-    static bool IsSentenceAtEnd( const SwTextNode& rTextNd );
+    static bool IsSentenceAtEnd(const SwTextFrame & rTextFrame);
 
     bool DoUnderline();
     bool DoTable();
@@ -231,23 +236,28 @@ SwTextFrame* SwAutoFormat::GetFrame( const SwTextNode& rTextNd ) const
 {
     // get the Frame
     const SwContentFrame *pFrame = rTextNd.getLayoutFrame( m_pEditShell->GetLayout() );
-    OSL_ENSURE( pFrame, "For Autoformat a Layout is needed" );
+    assert(pFrame && "For Autoformat a Layout is needed");
+    return EnsureFormatted(*static_cast<SwTextFrame const*>(pFrame));
+}
 
+SwTextFrame * SwAutoFormat::EnsureFormatted(SwTextFrame const& rFrame) const
+{
+    SwTextFrame *const pFrame(const_cast<SwTextFrame*>(&rFrame));
     if( m_aFlags.bAFormatByInput && !pFrame->isFrameAreaDefinitionValid() )
     {
-        DisableCallbackAction a(const_cast<SwRootFrame&>(*pFrame->getRootFrame()));
+        DisableCallbackAction a(*pFrame->getRootFrame());
         SwRect aTmpFrame( pFrame->getFrameArea() );
         SwRect aTmpPrt( pFrame->getFramePrintArea() );
         pFrame->Calc(pFrame->getRootFrame()->GetCurrShell()->GetOut());
 
         if( pFrame->getFrameArea() != aTmpFrame || pFrame->getFramePrintArea() != aTmpPrt ||
-            ( pFrame->IsTextFrame() && !const_cast<SwTextFrame*>(static_cast<const SwTextFrame*>(pFrame))->GetPaintSwRect().IsEmpty() ) )
+            !pFrame->GetPaintSwRect().IsEmpty())
         {
             pFrame->SetCompletePaint();
         }
     }
 
-    return const_cast<SwTextFrame*>(static_cast<const SwTextFrame*>(pFrame))->GetFormatted();
+    return pFrame->GetFormatted();
 }
 
 void SwAutoFormat::SetRedlineText_( sal_uInt16 nActionId )
@@ -285,7 +295,7 @@ void SwAutoFormat::SetRedlineText_( sal_uInt16 nActionId )
     m_pDoc->GetDocumentRedlineManager().SetAutoFormatRedlineComment( &sText, nSeqNo );
 }
 
-OUString SwAutoFormat::GoNextPara()
+void SwAutoFormat::GoNextPara()
 {
     SwNode* pNewNd = nullptr;
     do {
@@ -293,14 +303,14 @@ OUString SwAutoFormat::GoNextPara()
         if( m_aNdIdx.GetIndex() >= m_aEndNdIdx.GetIndex() )
         {
             m_bEnd = true;
-            return OUString();
+            return;
         }
 
-        ++m_aNdIdx;
+        sw::GotoNextLayoutTextFrame(m_aNdIdx, m_pEditShell->GetLayout());
         if( m_aNdIdx.GetIndex() >= m_aEndNdIdx.GetIndex() )
         {
             m_bEnd = true;
-            return OUString();
+            return;
         }
         else
             pNewNd = &m_aNdIdx.GetNode();
@@ -312,7 +322,7 @@ OUString SwAutoFormat::GoNextPara()
         if( pNewNd->IsEndNode() )
         {
             m_bEnd = true;
-            return OUString();
+            return;
         }
         else if( pNewNd->IsTableNode() )
             m_aNdIdx = *pNewNd->EndOfSectionNode();
@@ -330,10 +340,9 @@ OUString SwAutoFormat::GoNextPara()
 
     m_pCurTextNd = static_cast<SwTextNode*>(pNewNd);
     m_pCurTextFrame = GetFrame( *m_pCurTextNd );
-    return m_pCurTextNd->GetText();
 }
 
-bool SwAutoFormat::HasObjects( const SwNode& rNd )
+bool SwAutoFormat::HasObjects(const SwTextFrame & rFrame)
 {
     // Is there something bound to the paragraph in the paragraph
     // like Frames, DrawObjects, ...
@@ -344,7 +353,7 @@ bool SwAutoFormat::HasObjects( const SwNode& rNd )
         const SwFormatAnchor& rAnchor = pFrameFormat->GetAnchor();
         if ((RndStdIds::FLY_AT_PAGE != rAnchor.GetAnchorId()) &&
             rAnchor.GetContentAnchor() &&
-            &rAnchor.GetContentAnchor()->nNode.GetNode() == &rNd )
+            sw::FrameContainsNode(rFrame, rAnchor.GetContentAnchor()->nNode.GetIndex()))
         {
             bRet = true;
             break;
@@ -353,57 +362,61 @@ bool SwAutoFormat::HasObjects( const SwNode& rNd )
     return bRet;
 }
 
-const SwTextNode* SwAutoFormat::GetNextNode() const
+const SwTextFrame* SwAutoFormat::GetNextNode(bool const isCheckEnd) const
 {
-    if( m_aNdIdx.GetIndex()+1 >= m_aEndNdIdx.GetIndex() )
+    SwNodeIndex tmp(m_aNdIdx);
+    sw::GotoNextLayoutTextFrame(tmp, m_pEditShell->GetLayout());
+    if ((isCheckEnd && m_aEndNdIdx <= tmp) || !tmp.GetNode().IsTextNode())
         return nullptr;
-    return m_pDoc->GetNodes()[ m_aNdIdx.GetIndex() + 1 ]->GetTextNode();
+    // note: the returned frame is not necessarily formatted, have to call
+    // EnsureFormatted for that
+    return static_cast<SwTextFrame*>(tmp.GetNode().GetTextNode()->getLayoutFrame(m_pEditShell->GetLayout()));
 }
 
-bool SwAutoFormat::IsOneLine( const SwTextNode& rNd ) const
+bool SwAutoFormat::IsOneLine(const SwTextFrame & rFrame) const
 {
-    SwTextFrameInfo aFInfo( GetFrame( rNd ) );
+    SwTextFrameInfo aFInfo( EnsureFormatted(rFrame) );
     return aFInfo.IsOneLine();
 }
 
-bool SwAutoFormat::IsFastFullLine( const SwTextNode& rNd ) const
+bool SwAutoFormat::IsFastFullLine(const SwTextFrame & rFrame) const
 {
     bool bRet = m_aFlags.bRightMargin;
     if( bRet )
     {
-        SwTextFrameInfo aFInfo( GetFrame( rNd ) );
+        SwTextFrameInfo aFInfo( EnsureFormatted(rFrame) );
         bRet = aFInfo.IsFilled( m_aFlags.nRightMargin );
     }
     return bRet;
 }
 
-bool SwAutoFormat::IsEnumericChar( const SwTextNode& rNd ) const
+bool SwAutoFormat::IsEnumericChar(const SwTextFrame& rFrame) const
 {
-    const OUString& rText = rNd.GetText();
-    sal_Int32 nBlnks = GetLeadingBlanks( rText );
-    const sal_Int32 nLen = rText.getLength() - nBlnks;
+    const OUString& rText = rFrame.GetText();
+    TextFrameIndex nBlanks(GetLeadingBlanks(rText));
+    const TextFrameIndex nLen = TextFrameIndex(rText.getLength()) - nBlanks;
     if( !nLen )
         return false;
 
     // -, +, * separated by blank ??
-    if (2 < nLen && IsSpace(rText[nBlnks + 1]))
+    if (TextFrameIndex(2) < nLen && IsSpace(rText[sal_Int32(nBlanks) + 1]))
     {
-        if (StrChr(pBulletChar, rText[nBlnks]))
+        if (StrChr(pBulletChar, rText[sal_Int32(nBlanks)]))
             return true;
         // Should there be a symbol font at the position?
-        SwTextFrameInfo aFInfo( GetFrame( rNd ) );
-        if( aFInfo.IsBullet( nBlnks ))
+        SwTextFrameInfo aFInfo( EnsureFormatted(rFrame) );
+        if (aFInfo.IsBullet(nBlanks))
             return true;
     }
 
     // 1.) / 1. / 1.1.1 / (1). / (1) / ....
-    return USHRT_MAX != GetDigitLevel( rNd, nBlnks );
+    return USHRT_MAX != GetDigitLevel(rFrame, nBlanks);
 }
 
-bool SwAutoFormat::IsBlanksInString( const SwTextNode& rNd )
+bool SwAutoFormat::IsBlanksInString(const SwTextFrame& rFrame)
 {
     // Search more than 5 consecutive blanks/tabs in the string.
-    OUString sTmp( DelLeadingBlanks(rNd.GetText()) );
+    OUString sTmp( DelLeadingBlanks(rFrame.GetText()) );
     const sal_Int32 nLen = sTmp.getLength();
     sal_Int32 nIdx = 0;
     while (nIdx < nLen)
@@ -422,21 +435,23 @@ bool SwAutoFormat::IsBlanksInString( const SwTextNode& rNd )
     return false;
 }
 
-sal_uInt16 SwAutoFormat::CalcLevel( const SwTextNode& rNd, sal_uInt16 *pDigitLvl ) const
+sal_uInt16 SwAutoFormat::CalcLevel(const SwTextFrame & rFrame,
+        sal_uInt16 *const pDigitLvl) const
 {
     sal_uInt16 nLvl = 0, nBlnk = 0;
-    const OUString& rText = rNd.GetText();
+    const OUString& rText = rFrame.GetText();
     if( pDigitLvl )
         *pDigitLvl = USHRT_MAX;
 
-    if( RES_POOLCOLL_TEXT_MOVE == rNd.GetTextColl()->GetPoolFormatId() )
+    if (RES_POOLCOLL_TEXT_MOVE == rFrame.GetTextNodeForParaProps()->GetTextColl()->GetPoolFormatId())
     {
         ++nLvl;
     }
 
-    for (sal_Int32 n = 0, nEnd = rText.getLength(); n < nEnd; ++n)
+    for (TextFrameIndex n = TextFrameIndex(0),
+                     nEnd = TextFrameIndex(rText.getLength()); n < nEnd; ++n)
     {
-        switch (rText[n])
+        switch (rText[sal_Int32(n)])
         {
         case ' ':   if( 3 == ++nBlnk )
                     {
@@ -450,44 +465,49 @@ sal_uInt16 SwAutoFormat::CalcLevel( const SwTextNode& rNd, sal_uInt16 *pDigitLvl
         default:
             if( pDigitLvl )
                 // test 1.) / 1. / 1.1.1 / (1). / (1) / ....
-                *pDigitLvl = GetDigitLevel( rNd, n );
+                *pDigitLvl = GetDigitLevel(rFrame, n);
             return nLvl;
         }
     }
     return nLvl;
 }
 
-sal_Int32 SwAutoFormat::GetBigIndent( sal_Int32& rCurrentSpacePos ) const
+sal_Int32 SwAutoFormat::GetBigIndent(TextFrameIndex & rCurrentSpacePos) const
 {
-    SwTextFrameInfo aFInfo( GetFrame( *m_pCurTextNd ) );
-    const SwTextFrame* pNxtFrame = nullptr;
+    SwTextFrameInfo aFInfo( m_pCurTextFrame );
+    const SwTextFrame* pNextFrame = nullptr;
 
     if( !m_bMoreLines )
     {
-        const SwTextNode* pNxtNd = GetNextNode();
-        if( !CanJoin( pNxtNd ) || !IsOneLine( *pNxtNd ) )
+        pNextFrame = GetNextNode();
+        if (!CanJoin(pNextFrame) || !IsOneLine(*pNextFrame))
             return 0;
 
-        pNxtFrame = GetFrame( *pNxtNd );
+        pNextFrame = EnsureFormatted(*pNextFrame);
     }
 
-    return aFInfo.GetBigIndent( rCurrentSpacePos, pNxtFrame );
+    return aFInfo.GetBigIndent( rCurrentSpacePos, pNextFrame );
 }
 
-bool SwAutoFormat::IsNoAlphaLine( const SwTextNode& rNd ) const
+bool SwAutoFormat::IsNoAlphaLine(const SwTextFrame & rFrame) const
 {
-    const OUString& rStr = rNd.GetText();
+    const OUString& rStr = rFrame.GetText();
     if( rStr.isEmpty() )
         return false;
     // or better: determine via number of AlphaNum and !AlphaNum characters
     sal_Int32 nANChar = 0, nBlnk = 0;
 
-    CharClass& rCC = GetCharClass( rNd.GetSwAttrSet().GetLanguage().GetLanguage() );
-    for( sal_Int32 n = 0, nEnd = rStr.getLength(); n < nEnd; ++n )
-        if( IsSpace( rStr[ n ] ) )
+    for (TextFrameIndex n = TextFrameIndex(0),
+                     nEnd = TextFrameIndex(rStr.getLength()); n < nEnd; ++n)
+        if (IsSpace(rStr[sal_Int32(n)]))
             ++nBlnk;
-        else if( rCC.isLetterNumeric( rStr, n ))
-            ++nANChar;
+        else
+        {
+            auto const pair = rFrame.MapViewToModel(n);
+            CharClass& rCC = GetCharClass(pair.first->GetSwAttrSet().GetLanguage().GetLanguage());
+            if (rCC.isLetterNumeric(rStr, sal_Int32(n)))
+                ++nANChar;
+        }
 
     // If there are 75% of non-alphanumeric characters, then true
     sal_uLong nLen = rStr.getLength() - nBlnk;
@@ -500,7 +520,7 @@ bool SwAutoFormat::DoUnderline()
     if( !m_aFlags.bSetBorder )
         return false;
 
-    OUString const& rText(m_pCurTextNd->GetText());
+    OUString const& rText(m_pCurTextFrame->GetText());
     int eState = 0;
     sal_Int32 nCnt = 0;
     while (nCnt < rText.getLength())
@@ -527,9 +547,9 @@ bool SwAutoFormat::DoUnderline()
     if( 2 < nCnt )
     {
         // then underline the previous paragraph if one exists
-        DelEmptyLine( false );
+        DelEmptyLine( false ); // -> point will be on end of current paragraph
         m_aDelPam.SetMark();
-        m_aDelPam.GetMark()->nContent = 0;
+        *m_aDelPam.GetMark() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
 
         editeng::SvxBorderLine aLine;
         switch( eState )
@@ -567,7 +587,8 @@ bool SwAutoFormat::DoUnderline()
         aBox.SetLine( &aLine, SvxBoxItemLine::BOTTOM );
         aBox.SetDistance(42, SvxBoxItemLine::BOTTOM );     // ~0,75 mm
         aSet.Put(aBox);
-        m_pDoc->getIDocumentContentOperations().InsertItemSet( m_aDelPam, aSet );
+        m_pDoc->getIDocumentContentOperations().InsertItemSet(m_aDelPam, aSet,
+                SetAttrMode::DEFAULT, m_pEditShell->GetLayout());
 
         m_aDelPam.DeleteMark();
     }
@@ -580,24 +601,24 @@ bool SwAutoFormat::DoTable()
         m_pCurTextNd->FindTableNode() )
         return false;
 
-    const OUString& rTmp = m_pCurTextNd->GetText();
-    sal_Int32 nSttPlus = GetLeadingBlanks( rTmp );
-    sal_Int32 nEndPlus = GetTrailingBlanks( rTmp );
+    const OUString& rTmp = m_pCurTextFrame->GetText();
+    TextFrameIndex nSttPlus(GetLeadingBlanks(rTmp));
+    TextFrameIndex nEndPlus(GetTrailingBlanks(rTmp));
     sal_Unicode cChar;
 
-    if( 2 > nEndPlus - nSttPlus ||
-        ( '+' != ( cChar = rTmp[nSttPlus]) && '|' != cChar ) ||
-        ( '+' != ( cChar = rTmp[nEndPlus - 1]) && '|' != cChar ))
+    if (TextFrameIndex(2) > nEndPlus - nSttPlus
+        || ('+' != (cChar = rTmp[sal_Int32(nSttPlus)]) && '|' != cChar)
+        || ('+' != (cChar = rTmp[sal_Int32(nEndPlus) - 1]) && '|' != cChar))
         return false;
 
     SwTextFrameInfo aInfo( m_pCurTextFrame );
 
-    sal_Int32 n = nSttPlus;
+    TextFrameIndex n = nSttPlus;
     std::vector<sal_uInt16> aPosArr;
 
-    while (n < rTmp.getLength())
+    while (n < TextFrameIndex(rTmp.getLength()))
     {
-        switch (rTmp[n])
+        switch (rTmp[sal_Int32(n)])
         {
         case '-':
         case '_':
@@ -624,7 +645,7 @@ bool SwAutoFormat::DoTable()
         sal_uInt16 nColCnt = aPosArr.size() - 1;
         SwTwips nSttPos = aPosArr[ 0 ];
         sal_Int16 eHori;
-        switch( m_pCurTextNd->GetSwAttrSet().GetAdjust().GetAdjust() )
+        switch (m_pCurTextFrame->GetTextNodeForParaProps()->GetSwAttrSet().GetAdjust().GetAdjust())
         {
         case SvxAdjust::Center:     eHori = text::HoriOrientation::CENTER;    break;
         case SvxAdjust::Right:      eHori = text::HoriOrientation::RIGHT;     break;
@@ -697,15 +718,17 @@ sal_Int32 SwAutoFormat::GetTrailingBlanks( const OUString& rStr )
     return ++n;
 }
 
-bool SwAutoFormat::IsFirstCharCapital( const SwTextNode& rNd ) const
+bool SwAutoFormat::IsFirstCharCapital(const SwTextFrame& rFrame) const
 {
-    const OUString& rText = rNd.GetText();
-    for( sal_Int32 n = 0, nEnd = rText.getLength(); n < nEnd; ++n )
-        if (!IsSpace(rText[n]))
+    const OUString& rText = rFrame.GetText();
+    for (TextFrameIndex n = TextFrameIndex(0),
+                     nEnd = TextFrameIndex(rText.getLength()); n < nEnd; ++n)
+        if (!IsSpace(rText[sal_Int32(n)]))
         {
-            CharClass& rCC = GetCharClass( rNd.GetSwAttrSet().
+            auto const pair = rFrame.MapViewToModel(n);
+            CharClass& rCC = GetCharClass( pair.first->GetSwAttrSet().
                                         GetLanguage().GetLanguage() );
-            sal_Int32 nCharType = rCC.getCharacterType( rText, n );
+            sal_Int32 nCharType = rCC.getCharacterType(rText, sal_Int32(n));
             return CharClass::isLetterType( nCharType ) &&
                    0 != ( i18n::KCharacterType::UPPER &
                                                     nCharType );
@@ -713,12 +736,14 @@ bool SwAutoFormat::IsFirstCharCapital( const SwTextNode& rNd ) const
     return false;
 }
 
-sal_uInt16 SwAutoFormat::GetDigitLevel( const SwTextNode& rNd, sal_Int32& rPos,
+sal_uInt16
+SwAutoFormat::GetDigitLevel(const SwTextFrame& rFrame, TextFrameIndex& rPos,
         OUString* pPrefix, OUString* pPostfix, OUString* pNumTypes ) const
 {
+
     // check for 1.) / 1. / 1.1.1 / (1). / (1) / ....
-    const OUString& rText = rNd.GetText();
-    sal_Int32 nPos = rPos;
+    const OUString& rText = rFrame.GetText();
+    sal_Int32 nPos(rPos);
     int eScan = NONE;
 
     sal_uInt16 nStart = 0;
@@ -727,10 +752,10 @@ sal_uInt16 SwAutoFormat::GetDigitLevel( const SwTextNode& rNd, sal_Int32& rPos,
     sal_uInt16 nOpeningParentheses = 0;
     sal_uInt16 nClosingParentheses = 0;
 
-    CharClass& rCC = GetCharClass( rNd.GetSwAttrSet().GetLanguage().GetLanguage() );
-
     while (nPos < rText.getLength() && nDigitLvl < MAXLEVEL - 1)
     {
+        auto const pair = rFrame.MapViewToModel(TextFrameIndex(nPos));
+        CharClass& rCC = GetCharClass(pair.first->GetSwAttrSet().GetLanguage().GetLanguage());
         const sal_Unicode cCurrentChar = rText[nPos];
         if( ('0' <= cCurrentChar &&  '9' >= cCurrentChar) ||
             (0xff10 <= cCurrentChar &&  0xff19 >= cCurrentChar) )
@@ -949,7 +974,7 @@ CHECK_ROMAN_5:
             break;
         ++nPos;
     }
-    if( !( CHG & eScan ) || rPos == nPos ||
+    if (!( CHG & eScan ) || rPos == TextFrameIndex(nPos) ||
         nPos == rText.getLength() || !IsSpace(rText[nPos]) ||
         (nOpeningParentheses > nClosingParentheses))
         return USHRT_MAX;
@@ -957,15 +982,15 @@ CHECK_ROMAN_5:
     if( (NO_DELIM & eScan) && pPrefix )     // do not forget the last one
         *pPrefix += "\x01" + OUString::number( nStart );
 
-    rPos = nPos;
+    rPos = TextFrameIndex(nPos);
     return nDigitLvl;       // 0 .. 9 (MAXLEVEL - 1)
 }
 
 void SwAutoFormat::SetColl( sal_uInt16 nId, bool bHdLineOrText )
 {
     m_aDelPam.DeleteMark();
-    m_aDelPam.GetPoint()->nNode = m_aNdIdx;
-    m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, 0 );
+    m_aDelPam.GetPoint()->nNode = *m_pCurTextFrame->GetTextNodeForParaProps();
+    m_aDelPam.GetPoint()->nContent.Assign(m_aDelPam.GetPoint()->nNode.GetNode().GetContentNode(), 0);
 
     // keep hard tabs, alignment, language, hyphenation, DropCaps and nearly all frame attributes
     SfxItemSet aSet(
@@ -976,9 +1001,9 @@ void SwAutoFormat::SetColl( sal_uInt16 nId, bool bHdLineOrText )
             RES_PARATR_TABSTOP, RES_PARATR_DROP,
             RES_BACKGROUND, RES_SHADOW>{});
 
-    if( m_pCurTextNd->HasSwAttrSet() )
+    if (m_aDelPam.GetPoint()->nNode.GetNode().GetTextNode()->HasSwAttrSet())
     {
-        aSet.Put( *m_pCurTextNd->GetpSwAttrSet() );
+        aSet.Put(*m_aDelPam.GetPoint()->nNode.GetNode().GetTextNode()->GetpSwAttrSet());
         // take HeaderLine/TextBody only if centered or right aligned, otherwise only justification
         SvxAdjustItem const * pAdj;
         if( SfxItemState::SET == aSet.GetItemState( RES_PARATR_ADJUST,
@@ -995,33 +1020,29 @@ void SwAutoFormat::SetColl( sal_uInt16 nId, bool bHdLineOrText )
     m_pDoc->SetTextFormatCollByAutoFormat( *m_aDelPam.GetPoint(), nId, &aSet );
 }
 
-bool SwAutoFormat::HasSelBlanks( SwPaM& rPam )
+static bool HasSelBlanks(
+        SwTextFrame const*const pStartFrame, TextFrameIndex & rStartIndex,
+        SwTextFrame const*const pEndFrame, TextFrameIndex & rEndIndex)
 {
-    // Is there a Blank at the beginning or end?
-    // Do not delete it, it will be inserted again.
-    SwPosition * pPos = rPam.End();
-    sal_Int32 nBlnkPos = pPos->nContent.GetIndex();
-    SwTextNode* pTextNd = pPos->nNode.GetNode().GetTextNode();
-    if (nBlnkPos && nBlnkPos-- < pTextNd->GetText().getLength() &&
-        (' ' == pTextNd->GetText()[nBlnkPos]))
-        --pPos->nContent;
-    else
+    if (TextFrameIndex(0) < rEndIndex
+        && rEndIndex < TextFrameIndex(pEndFrame->GetText().getLength())
+        && ' ' == pEndFrame->GetText()[sal_Int32(rEndIndex) - 1])
     {
-        pPos = rPam.GetPoint() == pPos ? rPam.GetMark() : rPam.GetPoint();
-        nBlnkPos = pPos->nContent.GetIndex();
-        pTextNd = pPos->nNode.GetNode().GetTextNode();
-        if (nBlnkPos < pTextNd->GetText().getLength() &&
-            (' ' == pTextNd->GetText()[nBlnkPos]))
-            ++pPos->nContent;
-        else
-            return false;
+        --rEndIndex;
+        return true;
+    }
+    if (rStartIndex < TextFrameIndex(pStartFrame->GetText().getLength())
+        && ' ' == pStartFrame->GetText()[sal_Int32(rStartIndex)])
+    {
+        ++rStartIndex;
+        return true;
     }
-    return true;
+    return false;
 }
 
-bool SwAutoFormat::HasBreakAttr( const SwTextNode& rTextNd )
+bool SwAutoFormat::HasBreakAttr(const SwTextFrame& rTextFrame)
 {
-    const SfxItemSet* pSet = rTextNd.GetpSwAttrSet();
+    const SfxItemSet *const pSet = rTextFrame.GetTextNodeFirst()->GetpSwAttrSet();
     if( !pSet )
         return false;
 
@@ -1038,9 +1059,9 @@ bool SwAutoFormat::HasBreakAttr( const SwTextNode& rTextNd )
 }
 
 /// Is there a dot at the end?
-bool SwAutoFormat::IsSentenceAtEnd( const SwTextNode& rTextNd )
+bool SwAutoFormat::IsSentenceAtEnd(const SwTextFrame & rTextFrame)
 {
-    const OUString& rStr = rTextNd.GetText();
+    const OUString& rStr = rTextFrame.GetText();
     sal_Int32 n = rStr.getLength();
     if( !n )
         return true;
@@ -1059,23 +1080,22 @@ void SwAutoFormat::DeleteLeadingTrailingBlanks(bool bStart, bool bEnd)
     {
         // delete blanks at the end of the current and at the beginning of the next one
         m_aDelPam.DeleteMark();
-        m_aDelPam.GetPoint()->nNode = m_aNdIdx;
-        sal_Int32 nPos(0);
-        if( bStart && 0 != ( nPos = GetLeadingBlanks( m_pCurTextNd->GetText() )))
+        TextFrameIndex nPos(GetLeadingBlanks(m_pCurTextFrame->GetText()));
+        if (bStart && TextFrameIndex(0) != nPos)
         {
-            m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, 0 );
+            *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
             m_aDelPam.SetMark();
-            m_aDelPam.GetPoint()->nContent = nPos;
+            *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
             DeleteSel( m_aDelPam );
             m_aDelPam.DeleteMark();
         }
-        if (bEnd && m_pCurTextNd->GetText().getLength() !=
-                    ( nPos = GetTrailingBlanks( m_pCurTextNd->GetText() )) )
+        nPos = TextFrameIndex(GetTrailingBlanks(m_pCurTextFrame->GetText()));
+        if (bEnd && TextFrameIndex(m_pCurTextFrame->GetText().getLength()) != nPos)
         {
-            m_aDelPam.GetPoint()->nContent.Assign(
-                    m_pCurTextNd, m_pCurTextNd->GetText().getLength());
+            *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(
+                    TextFrameIndex(m_pCurTextFrame->GetText().getLength()));
             m_aDelPam.SetMark();
-            m_aDelPam.GetPoint()->nContent = nPos;
+            *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
             DeleteSel( m_aDelPam );
             m_aDelPam.DeleteMark();
         }
@@ -1156,39 +1176,43 @@ void SwAutoFormat::DeleteSelImpl(SwPaM & rDelPam, SwPaM & rPamToCorrect)
 
         m_aNdIdx = aTmp.GetPoint()->nNode;
         m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
+        m_pCurTextFrame = GetFrame(*m_pCurTextNd); // keep it up to date
     }
     else
         m_pEditShell->DeleteSel( rDelPam );
 }
 
-bool SwAutoFormat::DeleteJoinCurNextPara( const OUString& rNxtPara )
+bool SwAutoFormat::DeleteJoinCurNextPara(SwTextFrame const*const pNextFrame,
+        bool const bIgnoreLeadingBlanks)
 {
     // delete blanks at the end of the current and at the beginning of the next one
     m_aDelPam.DeleteMark();
-    m_aDelPam.GetPoint()->nNode = m_aNdIdx;
-    m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd,
-                    GetTrailingBlanks( m_pCurTextNd->GetText() ) );
-    m_aDelPam.SetMark();
+    TextFrameIndex nTrailingPos(GetTrailingBlanks(m_pCurTextFrame->GetText()));
 
-    ++m_aDelPam.GetPoint()->nNode;
-    SwTextNode* pTNd = m_aDelPam.GetNode().GetTextNode();
-    if( !pTNd )
+    SwTextFrame const*const pEndFrame(pNextFrame ? pNextFrame : m_pCurTextFrame);
+    TextFrameIndex nLeadingPos(0);
+    if (pNextFrame)
     {
-        // then delete only up to end of the paragraph
-        --m_aDelPam.GetPoint()->nNode;
-        m_aDelPam.GetPoint()->nContent = m_pCurTextNd->GetText().getLength();
+        nLeadingPos = TextFrameIndex(
+            bIgnoreLeadingBlanks ? 0 : GetLeadingBlanks(pNextFrame->GetText()));
     }
     else
-        m_aDelPam.GetPoint()->nContent.Assign( pTNd,
-                            GetLeadingBlanks( rNxtPara ));
+    {
+        nLeadingPos = TextFrameIndex(m_pCurTextFrame->GetText().getLength());
+    }
 
     // Is there a Blank at the beginning or end?
     // Do not delete it, it will be inserted again.
-    bool bHasBlnks = HasSelBlanks( m_aDelPam );
+    bool bHasBlnks = HasSelBlanks(m_pCurTextFrame, nTrailingPos, pEndFrame, nLeadingPos);
+
+    *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nTrailingPos);
+    m_aDelPam.SetMark();
+    *m_aDelPam.GetPoint() = pEndFrame->MapViewToModelPos(nLeadingPos);
 
     if( *m_aDelPam.GetPoint() != *m_aDelPam.GetMark() )
         DeleteSel( m_aDelPam );
     m_aDelPam.DeleteMark();
+    // note: keep m_aDelPam point at insert pos. for clients
 
     return !bHasBlnks;
 }
@@ -1198,31 +1222,32 @@ void SwAutoFormat::DelEmptyLine( bool bTstNextPara )
     SetRedlineText( STR_AUTOFMTREDL_DEL_EMPTY_PARA );
     // delete blanks in empty paragraph
     m_aDelPam.DeleteMark();
-    m_aDelPam.GetPoint()->nNode = m_aNdIdx;
-    m_aDelPam.GetPoint()->nContent.Assign(
-            m_pCurTextNd, m_pCurTextNd->GetText().getLength() );
+    *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(
+            TextFrameIndex(m_pCurTextFrame->GetText().getLength()));
     m_aDelPam.SetMark();
 
-    --m_aDelPam.GetMark()->nNode;
+    m_aDelPam.GetMark()->nNode = m_pCurTextFrame->GetTextNodeFirst()->GetIndex() - 1;
     SwTextNode* pTNd = m_aDelPam.GetNode( false ).GetTextNode();
     if( pTNd )
         // first use the previous text node
         m_aDelPam.GetMark()->nContent.Assign(pTNd, pTNd->GetText().getLength());
     else if( bTstNextPara )
     {
-        // then try the next (at the beginning of a Doc, table cells, borders, ...)
-        m_aDelPam.GetMark()->nNode += 2;
+        // then try the next (at the beginning of a Doc, table cells, frames, ...)
+        m_aDelPam.GetMark()->nNode = (m_pCurTextFrame->GetMergedPara()
+                    ? m_pCurTextFrame->GetMergedPara()->pLastNode
+                    : m_pCurTextNd
+                )->GetIndex() + 1;
         pTNd = m_aDelPam.GetNode( false ).GetTextNode();
         if( pTNd )
         {
             m_aDelPam.GetMark()->nContent.Assign( pTNd, 0 );
-            m_aDelPam.GetPoint()->nContent = 0;
+            *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
         }
     }
     else
     {
-        m_aDelPam.GetMark()->nNode = m_aNdIdx;
-        m_aDelPam.GetMark()->nContent = 0;
+        *m_aDelPam.GetMark() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
         pTNd = m_pCurTextNd;
     }
     if( pTNd )
@@ -1240,38 +1265,38 @@ void SwAutoFormat::DelMoreLinesBlanks( bool bWithLineBreaks )
     {
         // delete all blanks on the left and right of the indentation
         m_aDelPam.DeleteMark();
-        m_aDelPam.GetPoint()->nNode = m_aNdIdx;
-        m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, 0 );
 
         SwTextFrameInfo aFInfo( m_pCurTextFrame );
-        aFInfo.GetSpaces( m_aDelPam, !m_aFlags.bAFormatByInput || bWithLineBreaks );
+        std::vector<std::pair<TextFrameIndex, TextFrameIndex>> spaces;
+        aFInfo.GetSpaces(spaces, !m_aFlags.bAFormatByInput || bWithLineBreaks);
 
-        do {
-            SwPaM* pNxt = m_aDelPam.GetNext();
-            if( pNxt->HasMark() && *pNxt->GetPoint() != *pNxt->GetMark() )
+        for (auto & rSpaceRange : spaces)
+        {
+            assert(rSpaceRange.first != rSpaceRange.second);
+            bool const bHasBlanks = HasSelBlanks(
+                    m_pCurTextFrame, rSpaceRange.first,
+                    m_pCurTextFrame, rSpaceRange.second);
+            if (rSpaceRange.first != rSpaceRange.second)
             {
-                bool bHasBlnks = HasSelBlanks( *pNxt );
-                DeleteSel( *pNxt );
-                if( !bHasBlnks )
+                *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(rSpaceRange.first);
+                m_aDelPam.SetMark();
+                *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(rSpaceRange.second);
+                DeleteSel(m_aDelPam);
+                if (!bHasBlanks)
                 {
-                    m_pDoc->getIDocumentContentOperations().InsertString( *pNxt, OUString(' ') );
+                    m_pDoc->getIDocumentContentOperations().InsertString(m_aDelPam, OUString(' '));
                 }
+                m_aDelPam.DeleteMark();
             }
-
-            if( pNxt == &m_aDelPam )
-                break;
-            delete pNxt;
-        } while( true );
-
-        m_aDelPam.DeleteMark();
+        }
     }
 }
 
 void SwAutoFormat::JoinPrevPara()
 {
     m_aDelPam.DeleteMark();
-    m_aDelPam.GetPoint()->nNode = m_aNdIdx;
-    m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, 0 );
+    m_aDelPam.GetPoint()->nNode = *m_pCurTextFrame->GetTextNodeFirst();
+    m_aDelPam.GetPoint()->nContent.Assign(m_pCurTextFrame->GetTextNodeFirst(), 0);
     m_aDelPam.SetMark();
 
     --m_aDelPam.GetPoint()->nNode;
@@ -1294,29 +1319,30 @@ void SwAutoFormat::BuildIndent()
     if( m_bMoreLines )
         DelMoreLinesBlanks( true );
     else
-        bBreak = !IsFastFullLine( *m_pCurTextNd ) ||
-                IsBlanksInString( *m_pCurTextNd ) ||
-                IsSentenceAtEnd( *m_pCurTextNd );
+        bBreak = !IsFastFullLine(*m_pCurTextFrame)
+                || IsBlanksInString(*m_pCurTextFrame)
+                || IsSentenceAtEnd(*m_pCurTextFrame);
     SetColl( RES_POOLCOLL_TEXT_IDENT );
     if( !bBreak )
     {
         SetRedlineText( STR_AUTOFMTREDL_DEL_MORELINES );
-        const SwTextNode* pNxtNd = GetNextNode();
-        if( pNxtNd && !m_bEnd )
+        const SwTextFrame * pNextFrame = GetNextNode();
+        if (pNextFrame && !m_bEnd)
         {
             do {
-                bBreak = !IsFastFullLine( *pNxtNd ) ||
-                        IsBlanksInString( *pNxtNd ) ||
-                        IsSentenceAtEnd( *pNxtNd );
-                if (DeleteJoinCurNextPara(pNxtNd->GetText()))
+                bBreak = !IsFastFullLine(*pNextFrame)
+                    || IsBlanksInString(*pNextFrame)
+                    || IsSentenceAtEnd(*pNextFrame);
+                if (DeleteJoinCurNextPara(pNextFrame))
                 {
                     m_pDoc->getIDocumentContentOperations().InsertString( m_aDelPam, OUString(' ') );
                 }
                 if( bBreak )
                     break;
-                pNxtNd = GetNextNode();
-            } while( CanJoin( pNxtNd ) &&
-                    !CalcLevel( *pNxtNd ) );
+                pNextFrame = GetNextNode();
+            }
+            while (CanJoin(pNextFrame)
+                && !CalcLevel(*pNextFrame));
         }
     }
     DeleteLeadingTrailingBlanks();
@@ -1331,33 +1357,34 @@ sal_uInt16 SwAutoFormat::BuildTextIndent()
     if( m_bMoreLines )
         DelMoreLinesBlanks( true );
     else
-        bBreak = !IsFastFullLine( *m_pCurTextNd ) ||
-                    IsBlanksInString( *m_pCurTextNd ) ||
-                    IsSentenceAtEnd( *m_pCurTextNd );
+        bBreak = !IsFastFullLine(*m_pCurTextFrame)
+               || IsBlanksInString(*m_pCurTextFrame)
+               || IsSentenceAtEnd(*m_pCurTextFrame);
 
     sal_uInt16 nRet(0);
     if( m_aFlags.bAFormatByInput )
     {
-        nRet = CalcLevel( *m_pCurTextNd );
+        nRet = CalcLevel(*m_pCurTextFrame);
     }
 
     SetColl( RES_POOLCOLL_TEXT_MOVE );
     if( !bBreak )
     {
         SetRedlineText( STR_AUTOFMTREDL_DEL_MORELINES );
-        const SwTextNode* pNxtNd = GetNextNode();
-        while(  CanJoin( pNxtNd ) &&
-                CalcLevel( *pNxtNd ) )
+        const SwTextFrame * pNextFrame = GetNextNode();
+        while (CanJoin(pNextFrame) &&
+               CalcLevel(*pNextFrame))
         {
-            bBreak = !IsFastFullLine( *pNxtNd ) || IsBlanksInString( *pNxtNd ) ||
-                    IsSentenceAtEnd( *pNxtNd );
-            if (DeleteJoinCurNextPara(pNxtNd->GetText()))
+            bBreak = !IsFastFullLine(*pNextFrame)
+                    || IsBlanksInString(*pNextFrame)
+                    || IsSentenceAtEnd(*pNextFrame);
+            if (DeleteJoinCurNextPara(pNextFrame))
             {
                 m_pDoc->getIDocumentContentOperations().InsertString( m_aDelPam, OUString(' ') );
             }
             if( bBreak )
                 break;
-            pNxtNd = GetNextNode();
+            pNextFrame = GetNextNode();
         }
     }
     DeleteLeadingTrailingBlanks();
@@ -1373,28 +1400,29 @@ void SwAutoFormat::BuildText()
     if( m_bMoreLines )
         DelMoreLinesBlanks();
     else
-        bBreak = !IsFastFullLine( *m_pCurTextNd ) ||
-                    IsBlanksInString( *m_pCurTextNd ) ||
-                    IsSentenceAtEnd( *m_pCurTextNd );
+        bBreak = !IsFastFullLine(*m_pCurTextFrame)
+                || IsBlanksInString(*m_pCurTextFrame)
+                || IsSentenceAtEnd(*m_pCurTextFrame);
     SetColl( RES_POOLCOLL_TEXT, true );
     if( !bBreak )
     {
         SetRedlineText( STR_AUTOFMTREDL_DEL_MORELINES );
-        const SwTextNode* pNxtNd = GetNextNode();
-        while(  CanJoin( pNxtNd ) &&
-                !CalcLevel( *pNxtNd ) )
+        const SwTextFrame * pNextFrame = GetNextNode();
+        while (CanJoin(pNextFrame) &&
+               !CalcLevel(*pNextFrame))
         {
-            bBreak = !IsFastFullLine( *pNxtNd ) || IsBlanksInString( *pNxtNd ) ||
-                    IsSentenceAtEnd( *pNxtNd );
-            if (DeleteJoinCurNextPara(pNxtNd->GetText()))
+            bBreak = !IsFastFullLine(*pNextFrame)
+                    || IsBlanksInString(*pNextFrame)
+                    || IsSentenceAtEnd(*pNextFrame);
+            if (DeleteJoinCurNextPara(pNextFrame))
             {
                 m_pDoc->getIDocumentContentOperations().InsertString( m_aDelPam, OUString(' ') );
             }
             if( bBreak )
                 break;
-            const SwTextNode* pCurrNode = pNxtNd;
-            pNxtNd = GetNextNode();
-            if(!pNxtNd || pCurrNode == pNxtNd)
+            const SwTextFrame *const pCurrNode = pNextFrame;
+            pNextFrame = GetNextNode();
+            if (!pNextFrame || pCurrNode == pNextFrame)
                 break;
         }
     }
@@ -1412,24 +1440,24 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
     SwTwips nFrameWidth = m_pCurTextFrame->getFramePrintArea().Width();
     SwTwips nLeftTextPos;
     {
-        sal_Int32 nPos(0);
-        while (nPos < m_pCurTextNd->GetText().getLength() &&
-               IsSpace(m_pCurTextNd->GetText()[nPos]))
+        TextFrameIndex nPos(0);
+        while (nPos < TextFrameIndex(m_pCurTextFrame->GetText().getLength())
+               && IsSpace(m_pCurTextFrame->GetText()[sal_Int32(nPos)]))
         {
             ++nPos;
         }
 
         SwTextFrameInfo aInfo( m_pCurTextFrame );
         nLeftTextPos = aInfo.GetCharPos(nPos);
-        nLeftTextPos -= m_pCurTextNd->GetSwAttrSet().GetLRSpace().GetLeft();
+        nLeftTextPos -= m_pCurTextFrame->GetTextNodeForParaProps()->GetSwAttrSet().GetLRSpace().GetLeft();
     }
 
     if( m_bMoreLines )
         DelMoreLinesBlanks();
     else
-        bBreak = !IsFastFullLine( *m_pCurTextNd ) ||
-                    IsBlanksInString( *m_pCurTextNd ) ||
-                    IsSentenceAtEnd( *m_pCurTextNd );
+        bBreak = !IsFastFullLine(*m_pCurTextFrame)
+                || IsBlanksInString(*m_pCurTextFrame)
+                || IsSentenceAtEnd(*m_pCurTextFrame);
     bool bRTL = m_pEditShell->IsInRightToLeftText();
     DeleteLeadingTrailingBlanks();
 
@@ -1442,16 +1470,22 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
                      numfunc::GetDefaultPositionAndSpaceMode() );
 
     const SwNumRule* pCur = nullptr;
-    if( m_aFlags.bSetNumRule && nullptr != (pCur = m_pCurTextNd->GetNumRule()) )
-        aRule = *pCur;
+    if (m_aFlags.bSetNumRule)
+    {
+        pCur = m_pCurTextFrame->GetTextNodeForParaProps()->GetNumRule();
+        if (pCur)
+        {
+            aRule = *pCur;
+        }
+    }
 
     // replace bullet character with defined one
-    const OUString& rStr = m_pCurTextNd->GetText();
-    sal_Int32 nTextStt = 0;
+    const OUString& rStr = m_pCurTextFrame->GetText();
+    TextFrameIndex nTextStt(0);
     const sal_Unicode* pFndBulletChr = nullptr;
     if (m_aFlags.bChgEnumNum && 2 < rStr.getLength())
-        pFndBulletChr = StrChr(pBulletChar, rStr[nTextStt]);
-    if (nullptr != pFndBulletChr && IsSpace(rStr[nTextStt + 1]))
+        pFndBulletChr = StrChr(pBulletChar, rStr[sal_Int32(nTextStt)]);
+    if (nullptr != pFndBulletChr && IsSpace(rStr[sal_Int32(nTextStt) + 1]))
     {
         if( m_aFlags.bAFormatByInput )
         {
@@ -1528,8 +1562,9 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
         //             it is determined by the indentation level.
 
         OUString aPostfix, aPrefix, aNumTypes;
-        if( USHRT_MAX != ( nDigitLevel = GetDigitLevel( *m_pCurTextNd, nTextStt,
-                                        &aPrefix, &aPostfix, &aNumTypes )) )
+        nDigitLevel = GetDigitLevel(*m_pCurTextFrame, nTextStt,
+                                            &aPrefix, &aPostfix, &aNumTypes);
+        if (USHRT_MAX != nDigitLevel)
         {
             bChgEnum = true;
 
@@ -1620,37 +1655,41 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
     if ( bChgEnum || bChgBullet )
     {
         m_aDelPam.DeleteMark();
-        m_aDelPam.GetPoint()->nNode = m_aNdIdx;
+        m_aDelPam.GetPoint()->nNode = *m_pCurTextFrame->GetTextNodeForParaProps();
 
         if( m_aFlags.bSetNumRule )
         {
             if( m_aFlags.bAFormatByInput )
             {
                 m_aDelPam.SetMark();
-                ++m_aDelPam.GetMark()->nNode;
+                SwTextFrame const*const pNextFrame = GetNextNode(false);
+                assert(pNextFrame);
+                m_aDelPam.GetMark()->nNode = *pNextFrame->GetTextNodeForParaProps();
                 m_aDelPam.GetNode(false).GetTextNode()->SetAttrListLevel( nLvl );
             }
 
-            m_pCurTextNd->SetAttrListLevel(nLvl);
+            const_cast<SwTextNode*>(m_pCurTextFrame->GetTextNodeForParaProps())->SetAttrListLevel(nLvl);
 
             // start new list
-            m_pDoc->SetNumRule( m_aDelPam, aRule, true );
+            m_pDoc->SetNumRule(m_aDelPam, aRule, true, m_pEditShell->GetLayout());
             m_aDelPam.DeleteMark();
 
-            m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, 0 );
+            *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
         }
         else
-            m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd,
-                        bChgEnum ? nTextStt : 0 );
+        {
+            *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(
+                        bChgEnum ? nTextStt : TextFrameIndex(0));
+        }
         m_aDelPam.SetMark();
 
         if ( bChgBullet )
-            nTextStt += 2;
+            nTextStt += TextFrameIndex(2);
 
-        while( nTextStt < rStr.getLength() && IsSpace( rStr[ nTextStt ] ))
+        while (nTextStt < TextFrameIndex(rStr.getLength()) && IsSpace(rStr[sal_Int32(nTextStt)]))
             nTextStt++;
 
-        m_aDelPam.GetPoint()->nContent = nTextStt;
+        *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nTextStt);
         DeleteSel( m_aDelPam );
 
         if( !m_aFlags.bSetNumRule )
@@ -1661,11 +1700,12 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
             m_pDoc->getIDocumentContentOperations().InsertString( m_aDelPam, sChgStr );
 
             SfxItemSet aSet( m_pDoc->GetAttrPool(), aTextNodeSetRange );
+            *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
+            assert(&m_aDelPam.GetPoint()->nNode.GetNode() == m_pCurTextFrame->GetTextNodeForParaProps());
             if( bChgBullet )
             {
-                m_aDelPam.GetPoint()->nContent = 0;
                 m_aDelPam.SetMark();
-                m_aDelPam.GetMark()->nContent = 1;
+                *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(1));
                 SetAllScriptItem( aSet,
                      SvxFontItem( m_aFlags.aBulletFont.GetFamilyType(),
                                   m_aFlags.aBulletFont.GetFamilyName(),
@@ -1681,6 +1721,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
             SvxTabStopItem aTStops( RES_PARATR_TABSTOP );
             aTStops.Insert( SvxTabStop( 0 ) );
             aSet.Put( aTStops );
+            assert(&m_aDelPam.GetPoint()->nNode.GetNode() == m_pCurTextFrame->GetTextNodeForParaProps());
             m_pDoc->SetFormatItemByAutoFormat( m_aDelPam, aSet );
         }
     }
@@ -1691,22 +1732,23 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
         return;
     }
 
-    const SwTextNode* pNxtNd = GetNextNode();
-    while( CanJoin( pNxtNd ) &&
-            nLvl == CalcLevel( *pNxtNd ) )
+    const SwTextFrame * pNextFrame = GetNextNode();
+    while (CanJoin(pNextFrame)
+            && nLvl == CalcLevel(*pNextFrame))
     {
         SetRedlineText( STR_AUTOFMTREDL_DEL_MORELINES );
-        bBreak = !IsFastFullLine( *pNxtNd ) || IsBlanksInString( *pNxtNd ) ||
-                IsSentenceAtEnd( *pNxtNd );
-        if (DeleteJoinCurNextPara(pNxtNd->GetText()))
+        bBreak = !IsFastFullLine(*pNextFrame)
+                || IsBlanksInString(*pNextFrame)
+                || IsSentenceAtEnd(*pNextFrame);
+        if (DeleteJoinCurNextPara(pNextFrame))
         {
             m_pDoc->getIDocumentContentOperations().InsertString( m_aDelPam, OUString(' ') );
         }
         if( bBreak )
             break;
-        const SwTextNode* pCurrNode = pNxtNd;
-        pNxtNd = GetNextNode();
-        if(!pNxtNd || pCurrNode == pNxtNd)
+        const SwTextFrame *const pCurrNode = pNextFrame;
+        pNextFrame = GetNextNode();
+        if (!pNextFrame || pCurrNode == pNextFrame)
             break;
     }
     DeleteLeadingTrailingBlanks( false );
@@ -1720,14 +1762,14 @@ void SwAutoFormat::BuildNegIndent( SwTwips nSpaces )
 
     // read all succeeding paragraphs that belong to this enumeration
     bool bBreak = true;
-    sal_Int32 nSpacePos = 0;
+    TextFrameIndex nSpacePos(0);
     const sal_Int32 nTextPos = GetBigIndent( nSpacePos );
     if( m_bMoreLines )
         DelMoreLinesBlanks( true );
     else
-        bBreak = !IsFastFullLine( *m_pCurTextNd ) ||
-                    ( !nTextPos && IsBlanksInString( *m_pCurTextNd )) ||
-                    IsSentenceAtEnd( *m_pCurTextNd );
+        bBreak = !IsFastFullLine(*m_pCurTextFrame)
+            || (!nTextPos && IsBlanksInString(*m_pCurTextFrame))
+            || IsSentenceAtEnd(*m_pCurTextFrame);
 
     SetColl( static_cast<sal_uInt16>( nTextPos
                 ? RES_POOLCOLL_CONFRONTATION
@@ -1735,35 +1777,34 @@ void SwAutoFormat::BuildNegIndent( SwTwips nSpaces )
 
     if( nTextPos )
     {
-        const OUString& rStr = m_pCurTextNd->GetText();
+        const OUString& rStr = m_pCurTextFrame->GetText();
         bool bInsTab = true;
 
-        if ('\t' == rStr[nSpacePos+1]) // leave tab alone
+        if ('\t' == rStr[sal_Int32(nSpacePos) + 1]) // leave tab alone
         {
             --nSpacePos;
             bInsTab = false;
         }
 
-        sal_Int32 nSpaceStt = nSpacePos;
-        while (nSpaceStt && IsSpace(rStr[--nSpaceStt]))
+        TextFrameIndex nSpaceStt = nSpacePos;
+        while (nSpaceStt && IsSpace(rStr[sal_Int32(--nSpaceStt)]))
             ;
         ++nSpaceStt;
 
-        if (bInsTab && '\t' == rStr[nSpaceStt]) // leave tab alone
+        if (bInsTab && '\t' == rStr[sal_Int32(nSpaceStt)]) // leave tab alone
         {
             ++nSpaceStt;
             bInsTab = false;
         }
 
         m_aDelPam.DeleteMark();
-        m_aDelPam.GetPoint()->nNode = m_aNdIdx;
-        m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, nSpacePos );
+        *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nSpacePos);
 
         // delete old Spaces, etc.
         if( nSpaceStt < nSpacePos )
         {
             m_aDelPam.SetMark();
-            m_aDelPam.GetMark()->nContent = nSpaceStt;
+            *m_aDelPam.GetMark() = m_pCurTextFrame->MapViewToModelPos(nSpaceStt);
             DeleteSel( m_aDelPam );
             if( bInsTab )
             {
@@ -1776,22 +1817,22 @@ void SwAutoFormat::BuildNegIndent( SwTwips nSpaces )
     {
         SetRedlineText( STR_AUTOFMTREDL_DEL_MORELINES );
         SwTextFrameInfo aFInfo( m_pCurTextFrame );
-        const SwTextNode* pNxtNd = GetNextNode();
-        while(  CanJoin( pNxtNd ) &&
+        const SwTextFrame * pNextFrame = GetNextNode();
+        while (CanJoin(pNextFrame) &&
                 20 < std::abs( static_cast<long>(nSpaces - aFInfo.SetFrame(
-                                GetFrame( *pNxtNd ) ).GetLineStart() ))
+                                EnsureFormatted(*pNextFrame)).GetLineStart()) )
             )
         {
-            bBreak = !IsFastFullLine( *pNxtNd ) ||
-                    IsBlanksInString( *pNxtNd ) ||
-                    IsSentenceAtEnd( *pNxtNd );
-            if (DeleteJoinCurNextPara(pNxtNd->GetText()))
+            bBreak = !IsFastFullLine(*pNextFrame)
+                   || IsBlanksInString(*pNextFrame)
+                   || IsSentenceAtEnd(*pNextFrame);
+            if (DeleteJoinCurNextPara(pNextFrame))
             {
                 m_pDoc->getIDocumentContentOperations().InsertString( m_aDelPam, OUString(' ') );
             }
             if( bBreak )
                 break;
-            pNxtNd = GetNextNode();
+            pNextFrame = GetNextNode();
         }
     }
     DeleteLeadingTrailingBlanks();
@@ -1811,15 +1852,16 @@ void SwAutoFormat::BuildHeadLine( sal_uInt16 nLvl )
     SetColl( static_cast<sal_uInt16>(RES_POOLCOLL_HEADLINE1 + nLvl ), true );
     if( m_aFlags.bAFormatByInput )
     {
-        SwTextFormatColl& rNxtColl = m_pCurTextNd->GetTextColl()->GetNextTextFormatColl();
+        SwTextFormatColl& rNxtColl = m_pCurTextFrame->GetTextNodeForParaProps()->GetTextColl()->GetNextTextFormatColl();
 
         JoinPrevPara();
 
         DeleteLeadingTrailingBlanks( true, false );
-        (void)DeleteJoinCurNextPara( OUString() );
+        const SwTextFrame *const pNextFrame = GetNextNode(false);
+        (void)DeleteJoinCurNextPara(pNextFrame, true);
 
         m_aDelPam.DeleteMark();
-        m_aDelPam.GetPoint()->nNode = m_aNdIdx.GetIndex() + 1;
+        m_aDelPam.GetPoint()->nNode = *pNextFrame->GetTextNodeForParaProps();
         m_aDelPam.GetPoint()->nContent.Assign( m_aDelPam.GetContentNode(), 0 );
         m_pDoc->SetTextFormatColl( m_aDelPam, &rNxtColl );
     }
@@ -2142,7 +2184,7 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, SvxSwAutoFormatFlags const &
 
     bool bReplaceStyles = !m_aFlags.bAFormatByInput || m_aFlags.bReplaceStyles;
 
-    const SwTextNode* pNxtNd = nullptr;
+    const SwTextFrame * pNextFrame = nullptr;
     bool bNxtEmpty = false;
     bool bNxtAlpha = false;
     sal_uInt16 nNxtLevel = 0;
@@ -2152,15 +2194,18 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, SvxSwAutoFormatFlags const &
     if( pSttNd )
     {
         m_aNdIdx = *pSttNd;
-        --m_aNdIdx;           // for GoNextPara, one paragraph prior to that
+        // for GoNextPara, one paragraph prior to that
+        sw::GotoPrevLayoutTextFrame(m_aNdIdx, m_pEditShell->GetLayout());
         m_aEndNdIdx = *pEndNd;
-        ++m_aEndNdIdx;
+        sw::GotoNextLayoutTextFrame(m_aEndNdIdx, m_pEditShell->GetLayout());
 
         // check the previous TextNode
-        pNxtNd = m_aNdIdx.GetNode().GetTextNode();
-        bEmptyLine = !pNxtNd ||
-                    IsEmptyLine( *pNxtNd ) ||
-                    IsNoAlphaLine( *pNxtNd );
+        SwTextFrame const*const pPrevFrame = m_aNdIdx.GetNode().GetTextNode()
+            ? static_cast<SwTextFrame const*>(m_aNdIdx.GetNode().GetTextNode()->getLayoutFrame(m_pEditShell->GetLayout()))
+            : nullptr;
+        bEmptyLine = !pPrevFrame
+                    || IsEmptyLine(*pPrevFrame)
+                    || IsNoAlphaLine(*pPrevFrame);
     }
     else
         bEmptyLine = true;      // at document beginning
@@ -2228,16 +2273,19 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, SvxSwAutoFormatFlags const &
             break;
 
         case TST_EMPTY_LINE:
-            if( IsEmptyLine( *m_pCurTextNd ) )
+            if (IsEmptyLine(*m_pCurTextFrame))
             {
-                if( m_aFlags.bDelEmptyNode && !HasObjects( *m_pCurTextNd ) )
+                if (m_aFlags.bDelEmptyNode && !HasObjects(*m_pCurTextFrame))
                 {
                     bEmptyLine = true;
                     sal_uLong nOldCnt = m_pDoc->GetNodes().Count();
                     DelEmptyLine();
                     // Was there really a deletion of a node?
                     if( nOldCnt != m_pDoc->GetNodes().Count() )
-                        --m_aNdIdx;       // do not skip the next paragraph
+                    {
+                        // do not skip the next paragraph
+                        sw::GotoPrevLayoutTextFrame(m_aNdIdx, m_pEditShell->GetLayout());
+                    }
                 }
                 eStat = READ_NEXT_PARA;
             }
@@ -2246,7 +2294,7 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, SvxSwAutoFormatFlags const &
             break;
 
         case TST_ALPHA_LINE:
-            if( IsNoAlphaLine( *m_pCurTextNd ))
+            if (IsNoAlphaLine(*m_pCurTextFrame))
             {
                 // recognize a table definition +---+---+
                 if( m_aFlags.bAFormatByInput && m_aFlags.bCreateTable && DoTable() )
@@ -2275,7 +2323,7 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, SvxSwAutoFormatFlags const &
 
         case GET_ALL_INFO:
             {
-                if( m_pCurTextNd->GetNumRule() )
+                if (m_pCurTextFrame->GetTextNodeForParaProps()->GetNumRule())
                 {
                     // do nothing in numbering, go to next
                     bEmptyLine = false;
@@ -2289,7 +2337,7 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, SvxSwAutoFormatFlags const &
                 aFInfo.SetFrame( m_pCurTextFrame );
 
                 // so far: if there were templates assigned, keep these and go to next node
-                sal_uInt16 nPoolId = m_pCurTextNd->GetTextColl()->GetPoolFormatId();
+                sal_uInt16 nPoolId = m_pCurTextFrame->GetTextNodeForParaProps()->GetTextColl()->GetPoolFormatId();
                 if( IsPoolUserFormat( nPoolId )

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list