[Libreoffice-commits] core.git: 27 commits - sw/inc sw/qa sw/source xmloff/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Dec 18 16:57:58 UTC 2018


 sw/inc/crsrsh.hxx                                       |   21 
 sw/inc/editsh.hxx                                       |    2 
 sw/inc/pam.hxx                                          |   31 
 sw/inc/postithelper.hxx                                 |    5 
 sw/inc/reffld.hxx                                       |    3 
 sw/inc/swcrsr.hxx                                       |   21 
 sw/inc/txtftn.hxx                                       |    4 
 sw/qa/core/macros-test.cxx                              |    4 
 sw/qa/extras/uiwriter/uiwriter.cxx                      |    3 
 sw/source/core/crsr/crbm.cxx                            |   59 +
 sw/source/core/crsr/crsrsh.cxx                          |   16 
 sw/source/core/crsr/crstrvl.cxx                         |   12 
 sw/source/core/crsr/findattr.cxx                        |  302 +++++-
 sw/source/core/crsr/findcoll.cxx                        |   27 
 sw/source/core/crsr/findfmt.cxx                         |   45 
 sw/source/core/crsr/findtxt.cxx                         |  737 +++++++++++-----
 sw/source/core/crsr/pam.cxx                             |   40 
 sw/source/core/crsr/swcrsr.cxx                          |    9 
 sw/source/core/doc/DocumentContentOperationsManager.cxx |    9 
 sw/source/core/doc/DocumentRedlineManager.cxx           |  164 ++-
 sw/source/core/doc/docnum.cxx                           |   60 +
 sw/source/core/edit/acorrect.cxx                        |    2 
 sw/source/core/edit/autofmt.cxx                         |   11 
 sw/source/core/edit/eddel.cxx                           |    4 
 sw/source/core/edit/edfld.cxx                           |    9 
 sw/source/core/edit/editsh.cxx                          |   12 
 sw/source/core/edit/edtox.cxx                           |    2 
 sw/source/core/fields/postithelper.cxx                  |    8 
 sw/source/core/fields/reffld.cxx                        |   53 +
 sw/source/core/inc/acorrect.hxx                         |   10 
 sw/source/core/inc/ftnfrm.hxx                           |    4 
 sw/source/core/inc/pamtyp.hxx                           |   39 
 sw/source/core/inc/txtfrm.hxx                           |    4 
 sw/source/core/layout/frmtool.cxx                       |   36 
 sw/source/core/layout/wsfrm.cxx                         |   40 
 sw/source/core/text/EnhancedPDFExportHelper.cxx         |   22 
 sw/source/core/text/frmcrsr.cxx                         |    1 
 sw/source/core/text/itratr.cxx                          |   44 
 sw/source/core/text/itratr.hxx                          |    3 
 sw/source/core/text/redlnitr.cxx                        |   56 -
 sw/source/core/text/txtdrop.cxx                         |    3 
 sw/source/core/text/txtfrm.cxx                          |   36 
 sw/source/core/txtnode/atrftn.cxx                       |    3 
 sw/source/core/txtnode/ndtxt.cxx                        |    7 
 sw/source/core/undo/undel.cxx                           |    4 
 sw/source/filter/xml/XMLRedlineImportHelper.cxx         |   31 
 sw/source/filter/xml/swxml.cxx                          |   13 
 sw/source/filter/xml/wrtxml.cxx                         |   27 
 sw/source/filter/xml/xmlexp.cxx                         |    5 
 sw/source/ui/fldui/DropDownFieldDialog.cxx              |    2 
 sw/source/ui/fldui/fldedt.cxx                           |    2 
 sw/source/ui/fldui/inpdlg.cxx                           |    4 
 sw/source/ui/index/swuiidxmrk.cxx                       |    2 
 sw/source/uibase/docvw/PostItMgr.cxx                    |   18 
 sw/source/uibase/fldui/fldmgr.cxx                       |    4 
 sw/source/uibase/inc/wrtsh.hxx                          |    2 
 sw/source/uibase/uiview/view2.cxx                       |   21 
 sw/source/uibase/uiview/viewsrch.cxx                    |    3 
 sw/source/uibase/uiview/viewstat.cxx                    |    7 
 sw/source/uibase/uno/unotxdoc.cxx                       |   12 
 sw/source/uibase/wrtsh/move.cxx                         |    3 
 sw/source/uibase/wrtsh/select.cxx                       |    6 
 xmloff/source/core/xmlimp.cxx                           |    1 
 63 files changed, 1521 insertions(+), 629 deletions(-)

New commits:
commit 32902f66e7749b2d06d13f50416be5323a0c0ea9
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Fri Nov 30 17:54:41 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Dec 18 17:55:30 2018 +0100

    sw_redlinehide: make layout based Show/Hide mode the default
    
    remove ExperimentalMode checks
    
    Change-Id: Ie098eda0840bbd3231696cae43cc572ad61379fc

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 6563636a7a22..269e6b92d088 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -1534,8 +1534,11 @@ void SwUiWriterTest::testTdf83260()
     SwAutoCorrect corr(*SvxAutoCorrCfg::Get().GetAutoCorrect());
 
     // enabled but not shown
+    CPPUNIT_ASSERT(pWrtShell->GetLayout()->IsHideRedlines());
+#if 0
     CPPUNIT_ASSERT(IDocumentRedlineAccess::IsHideChanges(
             pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
+#endif
     CPPUNIT_ASSERT(IDocumentRedlineAccess::IsRedlineOn(
             pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
     CPPUNIT_ASSERT(!pDoc->getIDocumentRedlineAccess().GetRedlineTable().empty());
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 65c5450a43d8..e10fbcd6f9bf 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -2272,21 +2272,14 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, SvxSwAutoFormatFlags const &
                          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 = isExp
-            ? RedlineFlags::On | (eOldMode & RedlineFlags::ShowMask)
-            : RedlineFlags::On | RedlineFlags::ShowInsert;
+        eRedlMode = RedlineFlags::On | (eOldMode & RedlineFlags::ShowMask);
     }
     else
-      eRedlMode = isExp
-          ? RedlineFlags::Ignore | (eOldMode & RedlineFlags::ShowMask)
-          : RedlineFlags::ShowInsert | RedlineFlags::Ignore;
+      eRedlMode = RedlineFlags::Ignore | (eOldMode & RedlineFlags::ShowMask);
     m_pDoc->getIDocumentRedlineAccess().SetRedlineFlags( eRedlMode );
 
     // save undo state (might be turned off)
diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
index cec28a9b596a..d78e7e6b4849 100644
--- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx
+++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
@@ -344,19 +344,12 @@ XMLRedlineImportHelper::~XMLRedlineImportHelper()
         aAny <<= bShowChanges;
         if ( bHandleShowChanges )
         {
-            if (!utl::ConfigManager::IsFuzzing() && officecfg::Office::Common::Misc::ExperimentalMode::get(comphelper::getProcessComponentContext()))
-            {
-                aAny <<= true;
-                xModelPropertySet->setPropertyValue( g_sShowChanges, aAny );
-                // TODO maybe we need some property for the view-setting?
-                SwDoc *const pDoc(SwImport::GetDocFromXMLImport(m_rImport));
-                assert(pDoc);
-                pDoc->GetDocumentRedlineManager().SetHideRedlines(!bShowChanges);
-            }
-            else
-            {
-                xModelPropertySet->setPropertyValue( g_sShowChanges, aAny );
-            }
+            aAny <<= true;
+            xModelPropertySet->setPropertyValue( g_sShowChanges, aAny );
+            // TODO maybe we need some property for the view-setting?
+            SwDoc *const pDoc(SwImport::GetDocFromXMLImport(m_rImport));
+            assert(pDoc);
+            pDoc->GetDocumentRedlineManager().SetHideRedlines(!bShowChanges);
         }
         else
             xImportInfoPropertySet->setPropertyValue( g_sShowChanges, aAny );
diff --git a/sw/source/filter/xml/swxml.cxx b/sw/source/filter/xml/swxml.cxx
index f36ffb47a147..138dc19981c8 100644
--- a/sw/source/filter/xml/swxml.cxx
+++ b/sw/source/filter/xml/swxml.cxx
@@ -856,8 +856,7 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
     if( !(IsOrganizerMode() || IsBlockMode() || m_bInsertMode ||
           m_aOption.IsFormatsOnly() ||
             // sw_redlinehide: disable layout cache for now
-          (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext) &&
-            !*o3tl::doAccess<bool>(xInfoSet->getPropertyValue(sShowChanges)))))
+          !*o3tl::doAccess<bool>(xInfoSet->getPropertyValue(sShowChanges))))
     {
         try
         {
@@ -905,14 +904,8 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
     // tdf#83260 ensure that the first call of CompressRedlines after loading
     // the document is a no-op by calling it now
     rDoc.getIDocumentRedlineAccess().CompressRedlines();
-    if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
-    {   // can't set it on the layout or view shell because it doesn't exist yet
-        rDoc.GetDocumentRedlineManager().SetHideRedlines(!(nRedlineFlags & RedlineFlags::ShowDelete));
-    }
-    else
-    {
-        rDoc.getIDocumentRedlineAccess().SetRedlineFlags(nRedlineFlags);
-    }
+    // can't set it on the layout or view shell because it doesn't exist yet
+    rDoc.GetDocumentRedlineManager().SetHideRedlines(!(nRedlineFlags & RedlineFlags::ShowDelete));
 
     lcl_EnsureValidPam( rPaM ); // move Pam into valid content
 
diff --git a/sw/source/filter/xml/wrtxml.cxx b/sw/source/filter/xml/wrtxml.cxx
index 34e51e8f2ed9..495cd765aaa3 100644
--- a/sw/source/filter/xml/wrtxml.cxx
+++ b/sw/source/filter/xml/wrtxml.cxx
@@ -165,7 +165,6 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS
 
     xInfoSet->setPropertyValue( "TargetStorage", Any( xStg ) );
 
-    uno::Any aAny;
     if (m_bShowProgress)
     {
         // set progress range and start status indicator
@@ -188,15 +187,9 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS
     RedlineFlags const nOrigRedlineFlags = m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags();
     RedlineFlags nRedlineFlags(nOrigRedlineFlags);
     bool isShowChanges;
-    if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
-    {   // TODO: ideally this would be stored per-view...
-        SwRootFrame const*const pLayout(m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
-        isShowChanges = pLayout == nullptr || !pLayout->IsHideRedlines();
-    }
-    else
-    {
-        isShowChanges = IDocumentRedlineAccess::IsShowChanges(nRedlineFlags);
-    }
+    // TODO: ideally this would be stored per-view...
+    SwRootFrame const*const pLayout(m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
+    isShowChanges = pLayout == nullptr || !pLayout->IsHideRedlines();
     xInfoSet->setPropertyValue(sShowChanges, makeAny(isShowChanges));
     // ... and hide redlines for export
     nRedlineFlags &= ~RedlineFlags::ShowMask;
@@ -415,19 +408,10 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS
     xObjectResolver = nullptr;
 
     // restore redline mode
-    aAny = xInfoSet->getPropertyValue( sShowChanges );
     nRedlineFlags = m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags();
     nRedlineFlags &= ~RedlineFlags::ShowMask;
     nRedlineFlags |= RedlineFlags::ShowInsert;
-    if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
-    {
-        nRedlineFlags |= nOrigRedlineFlags & RedlineFlags::ShowMask;
-    }
-    else
-    {
-        if (*o3tl::doAccess<bool>(aAny))
-            nRedlineFlags |= RedlineFlags::ShowDelete;
-    }
+    nRedlineFlags |= nOrigRedlineFlags & RedlineFlags::ShowMask;
     m_pDoc->getIDocumentRedlineAccess().SetRedlineFlags( nRedlineFlags );
 
     if (xStatusIndicator.is())
diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx
index 0fd2296e97e8..3e408bed91bb 100644
--- a/sw/source/filter/xml/xmlexp.cxx
+++ b/sw/source/filter/xml/xmlexp.cxx
@@ -278,15 +278,8 @@ ErrCode SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
         }
     }
     RedlineFlags nRedlineFlags = RedlineFlags::NONE;
-    if (officecfg::Office::Common::Misc::ExperimentalMode::get(getComponentContext()))
-    {
-        SwRootFrame const*const pLayout(m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
-        m_bSavedShowChanges = pLayout == nullptr || !pLayout->IsHideRedlines();
-    }
-    else
-    {
-        m_bSavedShowChanges = IDocumentRedlineAccess::IsShowChanges( pDoc->getIDocumentRedlineAccess().GetRedlineFlags() );
-    }
+    SwRootFrame const*const pLayout(m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
+    m_bSavedShowChanges = pLayout == nullptr || !pLayout->IsHideRedlines();
     if( bSaveRedline )
     {
         // now save and switch redline mode
diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx
index 69224a69859d..524d636241af 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -654,17 +654,10 @@ void SwView::Execute(SfxRequest &rReq)
                 if( static_cast<const SfxBoolItem*>(pItem)->GetValue() )
                     nMode |= RedlineFlags::ShowDelete;
 
-                uno::Reference<uno::XComponentContext> const xContext(
-                        comphelper::getProcessComponentContext());
-                if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
-                {
-                    m_pWrtShell->GetLayout()->SetHideRedlines(
-                        !static_cast<const SfxBoolItem*>(pItem)->GetValue());
-                    if (m_pWrtShell->IsRedlineOn())
-                        m_pWrtShell->SetInsMode();
-                }
-                else
-                    m_pWrtShell->SetRedlineFlagsAndCheckInsMode( nMode );
+                m_pWrtShell->GetLayout()->SetHideRedlines(
+                    !static_cast<const SfxBoolItem*>(pItem)->GetValue());
+                if (m_pWrtShell->IsRedlineOn())
+                    m_pWrtShell->SetInsMode();
             }
             break;
         case FN_MAILMERGE_SENDMAIL_CHILDWINDOW:
diff --git a/sw/source/uibase/uiview/viewstat.cxx b/sw/source/uibase/uiview/viewstat.cxx
index 38ffb27df5da..909ba9a67225 100644
--- a/sw/source/uibase/uiview/viewstat.cxx
+++ b/sw/source/uibase/uiview/viewstat.cxx
@@ -284,12 +284,7 @@ void SwView::GetState(SfxItemSet &rSet)
             {
                 uno::Reference<uno::XComponentContext> const xContext(
                         comphelper::getProcessComponentContext());
-                if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
-                {
-                    rSet.Put(SfxBoolItem(nWhich, !m_pWrtShell->GetLayout()->IsHideRedlines()));
-                }
-                else
-                    rSet.Put( SfxBoolItem( nWhich, IDocumentRedlineAccess::IsShowChanges(m_pWrtShell->GetRedlineFlags()) ));
+                rSet.Put(SfxBoolItem(nWhich, !m_pWrtShell->GetLayout()->IsHideRedlines()));
             }
             break;
             case SID_AVMEDIA_PLAYER :
commit b310378e874bc8fa7005352fcd85fa64eb075f54
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Dec 5 16:37:18 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Dec 18 17:55:30 2018 +0100

    sw_redlinehide_4b: temporarily add an assert that is wrong
    
    This assert is wrong, because there may be a legimate need to query
    a position that is currently hidden.
    
    However, oddly enough, we haven't found a legitimate document yet that
    triggers this, and it has pointed us to several interesting functions
    that needed adapting to merged frames... so keep it a little while and
    remove it (and return something other than COMPLETE_STRING from mapping
    functions) later...
    
    Change-Id: Ide2abf0c2ce054b75c917063a5d5aa8d13430426

diff --git a/sw/source/core/text/frmcrsr.cxx b/sw/source/core/text/frmcrsr.cxx
index 7b6411163cb3..c756aedf4cd2 100644
--- a/sw/source/core/text/frmcrsr.cxx
+++ b/sw/source/core/text/frmcrsr.cxx
@@ -267,6 +267,7 @@ bool SwTextFrame::GetCharRect( SwRect& rOrig, const SwPosition &rPos,
 
         bool bGoOn = true;
         TextFrameIndex const nOffset = MapModelToViewPos(rPos);
+        assert(nOffset != TextFrameIndex(COMPLETE_STRING)); // not going to end well
         TextFrameIndex nNextOfst;
 
         do
commit 7f42b4de3a5a72e695da0705ddc7db8bce576901
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Dec 17 21:46:13 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Dec 18 17:55:30 2018 +0100

    sw_redlinehide_4b: ODF export: restore previous redline show flags
    
    There's a test for that, testRedlineFlags() in sw_globalfilter
    
    Change-Id: I9c821732910298d74271d95f0bfd0e902af84dbd

diff --git a/sw/source/filter/xml/wrtxml.cxx b/sw/source/filter/xml/wrtxml.cxx
index 0d5e53d4c319..34e51e8f2ed9 100644
--- a/sw/source/filter/xml/wrtxml.cxx
+++ b/sw/source/filter/xml/wrtxml.cxx
@@ -185,7 +185,8 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS
 
     // save show redline mode ...
     const OUString sShowChanges("ShowChanges");
-    RedlineFlags nRedlineFlags = m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags();
+    RedlineFlags const nOrigRedlineFlags = m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags();
+    RedlineFlags nRedlineFlags(nOrigRedlineFlags);
     bool isShowChanges;
     if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
     {   // TODO: ideally this would be stored per-view...
@@ -420,7 +421,7 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS
     nRedlineFlags |= RedlineFlags::ShowInsert;
     if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
     {
-        nRedlineFlags |= RedlineFlags::ShowDelete;
+        nRedlineFlags |= nOrigRedlineFlags & RedlineFlags::ShowMask;
     }
     else
     {
commit 5bc7fb209c0e6d7c6a46499d8c2e4d7abaa87bd7
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Dec 17 19:39:22 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Dec 18 17:55:30 2018 +0100

    sw_redlinehide_4b: export flag to flat-ODF
    
    Change-Id: Ief227f3f5b03ec186178f4d68c3a415969d65507

diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx
index 4887e14075fb..0fd2296e97e8 100644
--- a/sw/source/filter/xml/xmlexp.cxx
+++ b/sw/source/filter/xml/xmlexp.cxx
@@ -26,6 +26,7 @@
 #include <com/sun/star/xforms/XFormsSupplier.hpp>
 
 #include <o3tl/any.hxx>
+#include <officecfg/Office/Common.hxx>
 #include <sax/tools/converter.hxx>
 #include <svx/svdmodel.hxx>
 #include <svx/svdpage.hxx>
@@ -46,6 +47,7 @@
 #include <swmodule.hxx>
 #include <docsh.hxx>
 #include <viewsh.hxx>
+#include <rootfrm.hxx>
 #include <docstat.hxx>
 #include <swerror.h>
 #include <unotext.hxx>
@@ -276,7 +278,15 @@ ErrCode SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
         }
     }
     RedlineFlags nRedlineFlags = RedlineFlags::NONE;
-    m_bSavedShowChanges = IDocumentRedlineAccess::IsShowChanges( pDoc->getIDocumentRedlineAccess().GetRedlineFlags() );
+    if (officecfg::Office::Common::Misc::ExperimentalMode::get(getComponentContext()))
+    {
+        SwRootFrame const*const pLayout(m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
+        m_bSavedShowChanges = pLayout == nullptr || !pLayout->IsHideRedlines();
+    }
+    else
+    {
+        m_bSavedShowChanges = IDocumentRedlineAccess::IsShowChanges( pDoc->getIDocumentRedlineAccess().GetRedlineFlags() );
+    }
     if( bSaveRedline )
     {
         // now save and switch redline mode
commit 68d77adb2d8242588b416240e6f7d47940099aaa
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Dec 17 19:16:05 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Dec 18 17:55:29 2018 +0100

    sw_redlinehide_4b: xmloff: destroy TextImportHelper before Model
    
    nullpointer in ~XMLRedlineImportHelper in
    SwUiWriterTest::testThreadedException()
    
    Change-Id: Ic4a79ceffa831aced4db47836333a15a13773887

diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index d68a9debcfc2..556e39299454 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -431,6 +431,7 @@ void SvXMLImport::cleanup() throw ()
             pStylesContext->Clear();
         maContexts.pop();
     }
+    mxTextImport.clear(); // XMLRedlineImportHelper needs model
     DisposingModel();
 }
 
commit 87514172c1924492c33a8aa261b082f0ae7f9b48
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Dec 17 14:10:26 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Dec 18 17:55:29 2018 +0100

    sw_redlinehide_4b: adapt FindFormat()
    
    Change-Id: I78cfca1cd629bf518f8294450a34ee228a360ef9

diff --git a/sw/inc/swcrsr.hxx b/sw/inc/swcrsr.hxx
index 0ccba70839b9..d3d23155ff5e 100644
--- a/sw/inc/swcrsr.hxx
+++ b/sw/inc/swcrsr.hxx
@@ -123,7 +123,8 @@ public:
                 SwDocPositions nStart, SwDocPositions nEnde,
                 bool& bCancel,
                 FindRanges,
-                const SwTextFormatColl* pReplFormat );
+                const SwTextFormatColl* pReplFormat,
+                SwRootFrame const*const pLayout = nullptr);
     sal_uLong FindAttrs( const SfxItemSet& rSet, bool bNoCollections,
                 SwDocPositions nStart, SwDocPositions nEnde,
                 bool& bCancel,
diff --git a/sw/source/core/crsr/findcoll.cxx b/sw/source/core/crsr/findcoll.cxx
index b05fe2c5f742..ec033d6bb207 100644
--- a/sw/source/core/crsr/findcoll.cxx
+++ b/sw/source/core/crsr/findcoll.cxx
@@ -30,8 +30,13 @@
 struct SwFindParaFormatColl : public SwFindParas
 {
     const SwTextFormatColl *pFormatColl, *pReplColl;
-    SwFindParaFormatColl(const SwTextFormatColl& rFormatColl, const SwTextFormatColl* pRpColl)
-        : pFormatColl( &rFormatColl ), pReplColl( pRpColl )
+    SwRootFrame const* m_pLayout;
+    SwFindParaFormatColl(const SwTextFormatColl& rFormatColl,
+            const SwTextFormatColl *const pRpColl,
+            SwRootFrame const*const pLayout)
+        : pFormatColl( &rFormatColl )
+        , pReplColl( pRpColl )
+        , m_pLayout(pLayout)
     {}
     virtual ~SwFindParaFormatColl() {}
     virtual int DoFind(SwPaM &, SwMoveFnCollection const &, const SwPaM &, bool bInReadOnly) override;
@@ -45,11 +50,12 @@ int SwFindParaFormatColl::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnM
     if( bInReadOnly && pReplColl )
         bInReadOnly = false;
 
-    if (!sw::FindFormatImpl(rCursor, *pFormatColl, fnMove, rRegion, bInReadOnly))
+    if (!sw::FindFormatImpl(rCursor, *pFormatColl, fnMove, rRegion, bInReadOnly, m_pLayout))
         nRet = FIND_NOT_FOUND;
     else if( pReplColl )
     {
-        rCursor.GetDoc()->SetTextFormatColl(rCursor, const_cast<SwTextFormatColl*>(pReplColl));
+        rCursor.GetDoc()->SetTextFormatColl(rCursor,
+            const_cast<SwTextFormatColl*>(pReplColl), true, false, m_pLayout);
         nRet = FIND_NO_RING;
     }
     return nRet;
@@ -63,7 +69,8 @@ bool SwFindParaFormatColl::IsReplaceMode() const
 /// search for Format-Collections
 sal_uLong SwCursor::FindFormat( const SwTextFormatColl& rFormatColl, SwDocPositions nStart,
                           SwDocPositions nEnd, bool& bCancel,
-                          FindRanges eFndRngs, const SwTextFormatColl* pReplFormatColl )
+                          FindRanges eFndRngs, const SwTextFormatColl* pReplFormatColl,
+                          SwRootFrame const*const pLayout)
 {
     // switch off OLE-notifications
     SwDoc* pDoc = GetDoc();
@@ -83,7 +90,7 @@ sal_uLong SwCursor::FindFormat( const SwTextFormatColl& rFormatColl, SwDocPositi
                 &aRewriter );
     }
 
-    SwFindParaFormatColl aSwFindParaFormatColl(rFormatColl, pReplFormatColl);
+    SwFindParaFormatColl aSwFindParaFormatColl(rFormatColl, pReplFormatColl, pLayout);
 
     sal_uLong nRet = FindAll( aSwFindParaFormatColl, nStart, nEnd, eFndRngs, bCancel );
     pDoc->SetOle2Link( aLnk );
diff --git a/sw/source/core/crsr/findfmt.cxx b/sw/source/core/crsr/findfmt.cxx
index f45759e5a0d6..1193cf856ef8 100644
--- a/sw/source/core/crsr/findfmt.cxx
+++ b/sw/source/core/crsr/findfmt.cxx
@@ -20,13 +20,15 @@
 #include <doc.hxx>
 #include <pamtyp.hxx>
 #include <pam.hxx>
+#include <txtfrm.hxx>
 #include <memory>
 
 namespace sw {
 
 bool FindFormatImpl(SwPaM & rSearchPam,
         const SwFormat& rFormat, SwMoveFnCollection const & fnMove,
-        const SwPaM &rRegion, bool bInReadOnly)
+        const SwPaM &rRegion, bool bInReadOnly,
+        SwRootFrame const*const pLayout)
 {
     bool bFound = false;
     const bool bSrchForward = &fnMove == &fnMoveForward;
@@ -47,19 +49,37 @@ bool FindFormatImpl(SwPaM & rSearchPam,
 
     bool bFirst = true;
     SwContentNode* pNode;
-    while( nullptr != ( pNode = ::GetNode( *pPam, bFirst, fnMove, bInReadOnly )))
+    while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout)))
     {
-        if ( pNode->GetFormatColl() == &rFormat )
+        SwTextFrame const*const pFrame(pLayout && pNode->IsTextNode()
+            ? static_cast<SwTextFrame const*>(pNode->getLayoutFrame(pLayout))
+            : nullptr);
+        assert(!pLayout || !pNode->IsTextNode() || pFrame);
+        SwContentNode const& rPropsNode(*(pFrame
+            ? pFrame->GetTextNodeForParaProps()
+            : pNode));
+
+        if (rPropsNode.GetFormatColl() == &rFormat)
         {
             // if a FormatCollection is found then it is definitely a SwContentNode
 
             // FORWARD:  SPoint at the end, GetMark at the beginning of the node
             // BACKWARD: SPoint at the beginning, GetMark at the end of the node
             // always: incl. start and incl. end
-            *rSearchPam.GetPoint() = *pPam->GetPoint();
-            rSearchPam.SetMark();
-            pNode->MakeEndIndex( &rSearchPam.GetPoint()->nContent );
-            rSearchPam.GetMark()->nContent = 0;
+            if (pFrame)
+            {
+                *rSearchPam.GetPoint() = *pPam->GetPoint();
+                rSearchPam.SetMark();
+                *rSearchPam.GetMark() = pFrame->MapViewToModelPos(
+                    TextFrameIndex(bSrchForward ? pFrame->GetText().getLength() : 0));
+            }
+            else
+            {
+                *rSearchPam.GetPoint() = *pPam->GetPoint();
+                rSearchPam.SetMark();
+                pNode->MakeEndIndex( &rSearchPam.GetPoint()->nContent );
+                rSearchPam.GetMark()->nContent = 0;
+            }
 
             // if backward search, switch point and mark
             if( !bSrchForward )
diff --git a/sw/source/core/inc/pamtyp.hxx b/sw/source/core/inc/pamtyp.hxx
index b51212b23633..c9fc8124b876 100644
--- a/sw/source/core/inc/pamtyp.hxx
+++ b/sw/source/core/inc/pamtyp.hxx
@@ -95,7 +95,8 @@ namespace sw {
     bool FindFormatImpl(SwPaM & rSearchPam,
                 const SwFormat& rFormat,
                 SwMoveFnCollection const & fnMove,
-                const SwPaM & rRegion, bool bInReadOnly = false);
+                const SwPaM & rRegion, bool bInReadOnly,
+                SwRootFrame const* pLayout);
     bool FindAttrImpl(SwPaM & rSearchPam,
                 const SfxPoolItem& rAttr,
                 SwMoveFnCollection const & fnMove,
commit 1199902fc9cbf2cf51733f7bc4205d6c32d781d1
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Dec 17 13:13:46 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Dec 18 17:55:29 2018 +0100

    sw_redlinehide_4b: adapt FindAttrImpl()
    
    * rename the only user, some UpdateFields() overload, to UpateOneField()
    * restrict it to search for non-formatting hints; the FindAttrsImpl()
      should be used for formatting hints instead
    
    Change-Id: I15002610a287fcdcd76777733a277d2ce64904bc

diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index 6dd4c1ca9a9b..fba31cf0e9f0 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -397,7 +397,7 @@ public:
 
     void Insert2(SwField const &, const bool bForceExpandHints);
 
-    void UpdateFields( SwField & );   ///< One single field.
+    void UpdateOneField(SwField &);   ///< One single field.
 
     size_t GetFieldTypeCount(SwFieldIds nResId = SwFieldIds::Unknown) const;
     SwFieldType* GetFieldType(size_t nField, SwFieldIds nResId = SwFieldIds::Unknown) const;
diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx
index 30c15b43443c..2fa9c20cb01a 100644
--- a/sw/source/core/crsr/findattr.cxx
+++ b/sw/source/core/crsr/findattr.cxx
@@ -155,12 +155,11 @@ static void lcl_SetAttrPam( SwPaM& rPam, sal_Int32 nStart, const sal_Int32* pEnd
     @param rPam     ???
     @param rCmpItem ???
     @param fnMove   ???
-    @param bValue   ???
     @return Returns <true> if found, <false> otherwise.
 */
-static bool lcl_Search( const SwTextNode& rTextNd, SwPaM& rPam,
+static bool lcl_SearchAttr( const SwTextNode& rTextNd, SwPaM& rPam,
                     const SfxPoolItem& rCmpItem,
-                    SwMoveFnCollection const & fnMove, bool bValue )
+                    SwMoveFnCollection const & fnMove)
 {
     if ( !rTextNd.HasHints() )
         return false;
@@ -171,8 +170,7 @@ static bool lcl_Search( const SwTextNode& rTextNd, SwPaM& rPam,
     sal_Int32 nContentPos = rPam.GetPoint()->nContent.GetIndex();
 
     while( nullptr != ( pTextHt=(*fnMove.fnGetHint)(rTextNd.GetSwpHints(),nPos,nContentPos)))
-        if( pTextHt->Which() == rCmpItem.Which() &&
-            ( !bValue || CmpAttr( pTextHt->GetAttr(), rCmpItem )))
+        if (pTextHt->Which() == rCmpItem.Which())
         {
             lcl_SetAttrPam( rPam, pTextHt->GetStart(), pTextHt->End(), bForward );
             return true;
@@ -892,12 +890,14 @@ static bool lcl_Search( const SwContentNode& rCNd, const SfxItemSet& rCmpSet, bo
 namespace sw {
 
 bool FindAttrImpl(SwPaM & rSearchPam,
-        const SfxPoolItem& rAttr, bool bValue, SwMoveFnCollection const & fnMove,
-        const SwPaM & rRegion, bool bInReadOnly)
+        const SfxPoolItem& rAttr, SwMoveFnCollection const & fnMove,
+        const SwPaM & rRegion, bool bInReadOnly,
+        SwRootFrame const*const pLayout)
 {
     // determine which attribute is searched:
     const sal_uInt16 nWhich = rAttr.Which();
     bool bCharAttr = isCHRATR(nWhich) || isTXTATR(nWhich);
+    assert(isTXTATR(nWhich)); // sw_redlinehide: only works for non-formatting hints such as needed in UpdateFields; use FindAttrsImpl for others
 
     std::unique_ptr<SwPaM> pPam(sw::MakeRegion(fnMove, rRegion));
 
@@ -905,8 +905,6 @@ bool FindAttrImpl(SwPaM & rSearchPam,
     bool bFirst = true;
     const bool bSrchForward = &fnMove == &fnMoveForward;
     SwContentNode * pNode;
-    const SfxPoolItem* pItem;
-    SwpFormats aFormatArr;
 
     // if at beginning/end then move it out of the node
     if( bSrchForward
@@ -921,27 +919,73 @@ bool FindAttrImpl(SwPaM & rSearchPam,
         pPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() );
     }
 
-    while( nullptr != ( pNode = ::GetNode( *pPam, bFirst, fnMove, bInReadOnly ) ) )
+    while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout)))
     {
         if( bCharAttr )
         {
             if( !pNode->IsTextNode() ) // CharAttr are only in text nodes
                 continue;
 
-            if( pNode->GetTextNode()->HasHints() &&
-                lcl_Search( *pNode->GetTextNode(), *pPam, rAttr, fnMove,  bValue ))
+            SwTextFrame const*const pFrame(pLayout
+                ? static_cast<SwTextFrame const*>(pNode->getLayoutFrame(pLayout))
+                : nullptr);
+            if (pFrame)
+            {
+                SwTextNode const* pAttrNode(nullptr);
+                SwTextAttr const* pAttr(nullptr);
+                if (bSrchForward)
+                {
+                    sw::MergedAttrIter iter(*pFrame);
+                    do
+                    {
+                        pAttr = iter.NextAttr(&pAttrNode);
+                    }
+                    while (pAttr
+                        && (pAttrNode->GetIndex() < pPam->GetPoint()->nNode.GetIndex()
+                            || (pAttrNode->GetIndex() == pPam->GetPoint()->nNode.GetIndex()
+                                && pAttr->GetStart() < pPam->GetPoint()->nContent.GetIndex())
+                            || pAttr->Which() != nWhich));
+                }
+                else
+                {
+                    sw::MergedAttrIterReverse iter(*pFrame);
+                    do
+                    {
+                        pAttr = iter.PrevAttr(&pAttrNode);
+                    }
+                    while (pAttr
+                        && (pPam->GetPoint()->nNode.GetIndex() < pAttrNode->GetIndex()
+                            || (pPam->GetPoint()->nNode.GetIndex() == pAttrNode->GetIndex()
+                                && pPam->GetPoint()->nContent.GetIndex() <= pAttr->GetStart())
+                            || pAttr->Which() != nWhich));
+                }
+                if (pAttr)
+                {
+                    assert(pAttrNode);
+                    pPam->GetPoint()->nNode = *pAttrNode;
+                    lcl_SetAttrPam(*pPam, pAttr->GetStart(), pAttr->End(), bSrchForward);
+                    bFound = true;
+                    break;
+                }
+            }
+            else if (!pLayout && pNode->GetTextNode()->HasHints() &&
+                lcl_SearchAttr(*pNode->GetTextNode(), *pPam, rAttr, fnMove))
+            {
+                bFound = true;
+            }
+            if (bFound)
             {
                 // set to the values of the attribute
                 rSearchPam.SetMark();
                 *rSearchPam.GetPoint() = *pPam->GetPoint();
                 *rSearchPam.GetMark() = *pPam->GetMark();
-                bFound = true;
                 break;
             }
             else if (isTXTATR(nWhich))
                 continue;
         }
 
+#if 0
         // no hard attribution, so check if node was asked for this attr before
         if( !pNode->HasSwAttrSet() )
         {
@@ -952,7 +996,7 @@ bool FindAttrImpl(SwPaM & rSearchPam,
         }
 
         if( SfxItemState::SET == pNode->GetSwAttrSet().GetItemState( nWhich,
-            true, &pItem ) && ( !bValue || *pItem == rAttr ) )
+                true, &pItem ))
         {
             // FORWARD:  SPoint at the end, GetMark at the beginning of the node
             // BACKWARD: SPoint at the beginning, GetMark at the end of the node
@@ -963,6 +1007,7 @@ bool FindAttrImpl(SwPaM & rSearchPam,
             bFound = true;
             break;
         }
+#endif
     }
 
     // if backward search, switch point and mark
diff --git a/sw/source/core/edit/edfld.cxx b/sw/source/core/edit/edfld.cxx
index da0a15e0199e..3311439fd862 100644
--- a/sw/source/core/edit/edfld.cxx
+++ b/sw/source/core/edit/edfld.cxx
@@ -206,7 +206,7 @@ static SwTextField* lcl_FindInputField( SwDoc* pDoc, SwField& rField )
     return pTField;
 }
 
-void SwEditShell::UpdateFields( SwField &rField )
+void SwEditShell::UpdateOneField(SwField &rField)
 {
     SET_CURR_SHELL( this );
     StartAllAction();
@@ -261,9 +261,9 @@ void SwEditShell::UpdateFields( SwField &rField )
                 // Search for SwTextField ...
                 while(  bOkay
                      && pCurStt->nContent != pCurEnd->nContent
-                     && (sw::FindAttrImpl(aPam, aFieldHint, false, fnMoveForward, aCurPam, true)
-                          || sw::FindAttrImpl(aPam, aAnnotationFieldHint, false, fnMoveForward, aCurPam)
-                          || sw::FindAttrImpl(aPam, aInputFieldHint, false, fnMoveForward, aCurPam)))
+                     && (sw::FindAttrImpl(aPam, aFieldHint, fnMoveForward, aCurPam, true, GetLayout())
+                          || sw::FindAttrImpl(aPam, aAnnotationFieldHint, fnMoveForward, aCurPam, false, GetLayout())
+                          || sw::FindAttrImpl(aPam, aInputFieldHint, fnMoveForward, aCurPam, false, GetLayout())))
                 {
                     // if only one PaM has more than one field  ...
                     if( aPam.Start()->nContent != pCurStt->nContent )
diff --git a/sw/source/core/inc/pamtyp.hxx b/sw/source/core/inc/pamtyp.hxx
index a0ebf2bea708..b51212b23633 100644
--- a/sw/source/core/inc/pamtyp.hxx
+++ b/sw/source/core/inc/pamtyp.hxx
@@ -97,9 +97,10 @@ namespace sw {
                 SwMoveFnCollection const & fnMove,
                 const SwPaM & rRegion, bool bInReadOnly = false);
     bool FindAttrImpl(SwPaM & rSearchPam,
-                const SfxPoolItem& rAttr, bool bValue,
+                const SfxPoolItem& rAttr,
                 SwMoveFnCollection const & fnMove,
-                const SwPaM & rPam, bool bInReadOnly = false);
+                const SwPaM & rPam, bool bInReadOnly,
+                SwRootFrame const* pLayout);
 
 } // namespace sw
 
diff --git a/sw/source/ui/fldui/DropDownFieldDialog.cxx b/sw/source/ui/fldui/DropDownFieldDialog.cxx
index 5ccead9f8504..387bccc39490 100644
--- a/sw/source/ui/fldui/DropDownFieldDialog.cxx
+++ b/sw/source/ui/fldui/DropDownFieldDialog.cxx
@@ -96,7 +96,7 @@ void sw::DropDownFieldDialog::Apply()
                 static_cast<SwDropDownField*>(m_pDropField->CopyField().release()));
 
             pCopy->SetPar1(sSelect);
-            m_rSh.SwEditShell::UpdateFields(*pCopy);
+            m_rSh.SwEditShell::UpdateOneField(*pCopy);
 
             m_rSh.SetUndoNoResetModified();
             m_rSh.EndAllAction();
diff --git a/sw/source/ui/fldui/fldedt.cxx b/sw/source/ui/fldui/fldedt.cxx
index dfbb9e08183e..8578da18e2d4 100644
--- a/sw/source/ui/fldui/fldedt.cxx
+++ b/sw/source/ui/fldui/fldedt.cxx
@@ -333,7 +333,7 @@ IMPL_LINK_NOARG(SwFieldEditDlg, AddressHdl, Button*, void)
     ScopedVclPtr<SfxAbstractDialog> pDlg(rFact.CreateSwAddressAbstractDlg(this, aSet));
     if (RET_OK == pDlg->Execute())
     {
-        pSh->UpdateFields( *pCurField );
+        pSh->UpdateOneField(*pCurField);
     }
 }
 
diff --git a/sw/source/ui/fldui/inpdlg.cxx b/sw/source/ui/fldui/inpdlg.cxx
index 361d14a184a8..f2bc3de52fe2 100644
--- a/sw/source/ui/fldui/inpdlg.cxx
+++ b/sw/source/ui/fldui/inpdlg.cxx
@@ -133,14 +133,14 @@ void SwFieldInputDlg::Apply()
         else if( aTmp != pInpField->GetPar1() )
         {
             pInpField->SetPar1(aTmp);
-            rSh.SwEditShell::UpdateFields(*pInpField);
+            rSh.SwEditShell::UpdateOneField(*pInpField);
             bModified = true;
         }
     }
     else if( aTmp != pSetField->GetPar2())
     {
         pSetField->SetPar2(aTmp);
-        rSh.SwEditShell::UpdateFields(*pSetField);
+        rSh.SwEditShell::UpdateOneField(*pSetField);
         bModified = true;
     }
 
diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx
index 892fae5561e0..b25e57b13f39 100644
--- a/sw/source/uibase/fldui/fldmgr.cxx
+++ b/sw/source/uibase/fldui/fldmgr.cxx
@@ -1518,7 +1518,7 @@ bool SwFieldMgr::InsertField(
     if(bTable)
     {
         pCurShell->Left(CRSR_SKIP_CHARS, false, 1, false );
-        pCurShell->UpdateFields(*pField);
+        pCurShell->UpdateOneField(*pField);
         pCurShell->Right(CRSR_SKIP_CHARS, false, 1, false );
     }
     else if( bPageVar )
@@ -1690,7 +1690,7 @@ void SwFieldMgr::UpdateCurField(sal_uInt32 nFormat,
     }
     else {
         // mb: #32157
-        pSh->SwEditShell::UpdateFields(*pTmpField);
+        pSh->SwEditShell::UpdateOneField(*pTmpField);
         GetCurField();
     }
 
commit 4caef398af256be5f0c2a159129b528ee3702e5c
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Thu Dec 13 15:49:10 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Dec 18 17:55:29 2018 +0100

    sw_redlinehide_4b: adapt FindAttrs()
    
    Iterate over merged nodes, and iterate over extents in them, so the
    complex attribute-finding logic doesn't need to be changed.
    
    Change-Id: Id72ca9247165a0c93f0cf2a38b7a0249771ca2eb

diff --git a/sw/inc/swcrsr.hxx b/sw/inc/swcrsr.hxx
index c46dbde27b7b..0ccba70839b9 100644
--- a/sw/inc/swcrsr.hxx
+++ b/sw/inc/swcrsr.hxx
@@ -129,7 +129,8 @@ public:
                 bool& bCancel,
                 FindRanges,
                 const i18nutil::SearchOptions2* pSearchOpt,
-                const SfxItemSet* rReplSet = nullptr );
+                const SfxItemSet* rReplSet = nullptr,
+                SwRootFrame const*const pLayout = nullptr);
 
     // UI versions
     bool IsStartEndSentence(bool bEnd, SwRootFrame const* pLayout) const;
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 1fe8fa72e92f..18b2d348e5c0 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -3368,7 +3368,7 @@ sal_uLong SwCursorShell::FindAttrs( const SfxItemSet& rSet,
     m_pTableCursor = nullptr;
     SwCallLink aLk( *this ); // watch Cursor-Moves; call Link if needed
     sal_uLong nRet = m_pCurrentCursor->FindAttrs(rSet, bNoCollections, eStart, eEnd,
-                                     bCancel, eRng, pSearchOpt, rReplSet );
+                         bCancel, eRng, pSearchOpt, rReplSet, GetLayout());
     if( nRet )
         UpdateCursor();
     return nRet;
diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx
index f72f9e2856b9..30c15b43443c 100644
--- a/sw/source/core/crsr/findattr.cxx
+++ b/sw/source/core/crsr/findattr.cxx
@@ -42,6 +42,7 @@
 #include <editsh.hxx>
 #include <ndtxt.hxx>
 #include <pamtyp.hxx>
+#include <txtfrm.hxx>
 #include <swundo.hxx>
 #include <boost/optional.hpp>
 
@@ -977,7 +978,8 @@ typedef bool (*FnSearchAttr)( const SwTextNode&, SwAttrCheckArr&, SwPaM& );
 
 static bool FindAttrsImpl(SwPaM & rSearchPam,
         const SfxItemSet& rSet, bool bNoColls, SwMoveFnCollection const & fnMove,
-        const SwPaM & rRegion, bool bInReadOnly, bool bMoveFirst)
+        const SwPaM & rRegion, bool bInReadOnly, bool bMoveFirst,
+        SwRootFrame const*const pLayout)
 {
     std::unique_ptr<SwPaM> pPam(sw::MakeRegion(fnMove, rRegion));
 
@@ -1011,22 +1013,100 @@ static bool FindAttrsImpl(SwPaM & rSearchPam,
         pPam->GetPoint()->nContent.Assign( pNd, bSrchForward ? 0 : pNd->Len() );
     }
 
-    while( nullptr != ( pNode = ::GetNode( *pPam, bFirst, fnMove, bInReadOnly ) ) )
+    while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout)))
     {
+        SwTextFrame const*const pFrame(pLayout && pNode->IsTextNode()
+            ? static_cast<SwTextFrame const*>(pNode->getLayoutFrame(pLayout))
+            : nullptr);
+        assert(!pLayout || !pNode->IsTextNode() || pFrame);
+        // sw_redlinehide: it's apparently not possible to find break items
+        // with the UI, so checking one node is enough
+        SwContentNode const& rPropsNode(*(pFrame
+            ? pFrame->GetTextNodeForParaProps()
+            : pNode));
+
         if( aCmpArr.Count() )
         {
             if( !pNode->IsTextNode() ) // CharAttr are only in text nodes
                 continue;
 
-            if( (!aOtherSet.Count() ||
-                lcl_Search( *pNode, aOtherSet, bNoColls )) &&
-                (*fnSearch)( *pNode->GetTextNode(), aCmpArr, *pPam ))
+            if (aOtherSet.Count() &&
+                !lcl_Search(rPropsNode, aOtherSet, bNoColls))
+            {
+                continue;
+            }
+            sw::MergedPara const*const pMergedPara(pFrame ? pFrame->GetMergedPara() : nullptr);
+            if (pMergedPara)
+            {
+                SwPosition const& rStart(*pPam->Start());
+                SwPosition const& rEnd(*pPam->End());
+                // no extents? fall back to searching index 0 of propsnode
+                // to find its node items
+                if (pMergedPara->extents.empty())
+                {
+                    if (rStart.nNode.GetIndex() <= rPropsNode.GetIndex()
+                        && rPropsNode.GetIndex() <= rEnd.nNode.GetIndex())
+                    {
+                        SwPaM tmp(rPropsNode, 0, rPropsNode, 0);
+                        bFound = (*fnSearch)(*pNode->GetTextNode(), aCmpArr, tmp);
+                        if (bFound)
+                        {
+                            *pPam = tmp;
+                        }
+                    }
+                }
+                else
+                {
+                    // iterate the extents, and intersect with input pPam:
+                    // the found ranges should never include delete redlines
+                    // so that subsequent Replace will not affect them
+                    for (size_t i = 0; i < pMergedPara->extents.size(); ++i)
+                    {
+                        auto const rExtent(pMergedPara->extents[bSrchForward
+                                ? i
+                                : pMergedPara->extents.size() - i - 1]);
+                        if (rExtent.pNode->GetIndex() < rStart.nNode.GetIndex()
+                            || rEnd.nNode.GetIndex() < rExtent.pNode->GetIndex())
+                        {
+                            continue;
+                        }
+                        sal_Int32 const nStart(rExtent.pNode == &rStart.nNode.GetNode()
+                                ? rStart.nContent.GetIndex()
+                                : 0);
+                        if (rExtent.nEnd <= nStart)
+                        {
+                            continue;
+                        }
+                        sal_Int32 const nEnd(rExtent.pNode == &rEnd.nNode.GetNode()
+                                ? rEnd.nContent.GetIndex()
+                                : rExtent.pNode->Len());
+                        if (nEnd < rExtent.nStart
+                            || (nStart != nEnd && nEnd == rExtent.nStart))
+                        {
+                            continue;
+                        }
+                        SwPaM tmp(*rExtent.pNode, std::max(nStart, rExtent.nStart),
+                            *rExtent.pNode, std::min(nEnd, rExtent.nEnd));
+                        tmp.Normalize(bSrchForward);
+                        bFound = (*fnSearch)(*rExtent.pNode, aCmpArr, tmp);
+                        if (bFound)
+                        {
+                            *pPam = tmp;
+                            break;
+                        }
+                    }
+                }
+            }
+            else
+            {
+                bFound = (*fnSearch)(*pNode->GetTextNode(), aCmpArr, *pPam);
+            }
+            if (bFound)
             {
                 // set to the values of the attribute
                 rSearchPam.SetMark();
                 *rSearchPam.GetPoint() = *pPam->GetPoint();
                 *rSearchPam.GetMark() = *pPam->GetMark();
-                bFound = true;
                 break;
             }
             continue; // text attribute
@@ -1036,22 +1116,39 @@ static bool FindAttrsImpl(SwPaM & rSearchPam,
             continue;
 
         // no hard attribution, so check if node was asked for this attr before
-        if( !pNode->HasSwAttrSet() )
+        // (as an optimisation)
+        if (!rPropsNode.HasSwAttrSet())
         {
-            SwFormat* pTmpFormat = pNode->GetFormatColl();
+            SwFormat* pTmpFormat = rPropsNode.GetFormatColl();
             if( aFormatArr.find( pTmpFormat ) != aFormatArr.end() )
                 continue; // collection was requested earlier
             aFormatArr.insert( pTmpFormat );
         }
 
-        if( lcl_Search( *pNode, aOtherSet, bNoColls ))
+        if (lcl_Search(rPropsNode, aOtherSet, bNoColls))
         {
             // FORWARD:  SPoint at the end, GetMark at the beginning of the node
             // BACKWARD: SPoint at the beginning, GetMark at the end of the node
-            // always: incl. start and incl. end
-            *rSearchPam.GetPoint() = *pPam->GetPoint();
-            rSearchPam.SetMark();
-            pNode->MakeEndIndex( &rSearchPam.GetPoint()->nContent );
+            if (pFrame)
+            {
+                *rSearchPam.GetPoint() = *pPam->GetPoint();
+                rSearchPam.SetMark();
+                *rSearchPam.GetMark() = pFrame->MapViewToModelPos(
+                    TextFrameIndex(bSrchForward ? pFrame->GetText().getLength() : 0));
+            }
+            else
+            {
+                *rSearchPam.GetPoint() = *pPam->GetPoint();
+                rSearchPam.SetMark();
+                if (bSrchForward)
+                {
+                    pNode->MakeEndIndex( &rSearchPam.GetPoint()->nContent );
+                }
+                else
+                {
+                    pNode->MakeStartIndex( &rSearchPam.GetPoint()->nContent );
+                }
+            }
             bFound = true;
             break;
         }
@@ -1067,17 +1164,23 @@ static bool FindAttrsImpl(SwPaM & rSearchPam,
 /// parameters for search for attributes
 struct SwFindParaAttr : public SwFindParas
 {
-    bool const bValue;
+    bool const m_bNoCollection;
     const SfxItemSet *pSet, *pReplSet;
     const i18nutil::SearchOptions2 *pSearchOpt;
     SwCursor& m_rCursor;
+    SwRootFrame const* m_pLayout;
     std::unique_ptr<utl::TextSearch> pSText;
 
     SwFindParaAttr( const SfxItemSet& rSet, bool bNoCollection,
                     const i18nutil::SearchOptions2* pOpt, const SfxItemSet* pRSet,
-                    SwCursor& rCursor )
-        : bValue( bNoCollection ), pSet( &rSet ), pReplSet( pRSet ),
-          pSearchOpt( pOpt ), m_rCursor( rCursor ) {}
+                    SwCursor& rCursor, SwRootFrame const*const pLayout)
+        : m_bNoCollection(bNoCollection)
+        , pSet( &rSet )
+        , pReplSet( pRSet )
+        , pSearchOpt( pOpt )
+        , m_rCursor(rCursor)
+        , m_pLayout(pLayout)
+    {}
 
     virtual ~SwFindParaAttr()   {}
 
@@ -1107,7 +1210,7 @@ int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
             if( pSet->Count() ) // any attributes?
             {
                 // first attributes
-                if (!FindAttrsImpl(aSrchPam, *pSet, bValue, fnMove, aRegion, bInReadOnly, bMoveFirst))
+                if (!FindAttrsImpl(aSrchPam, *pSet, m_bNoCollection, fnMove, aRegion, bInReadOnly, bMoveFirst, m_pLayout))
                     return FIND_NOT_FOUND;
                 bMoveFirst = true;
 
@@ -1136,7 +1239,7 @@ int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
             // TODO: searching for attributes in Outliner text?!
 
             // continue search in correct section (pTextRegion)
-            if (sw::FindTextImpl(aSrchPam, *pSearchOpt, false/*bSearchInNotes*/, *pSText, fnMove, *pTextRegion, bInReadOnly, nullptr/*FIXME*/) &&
+            if (sw::FindTextImpl(aSrchPam, *pSearchOpt, false/*bSearchInNotes*/, *pSText, fnMove, *pTextRegion, bInReadOnly, m_pLayout) &&
                 *aSrchPam.GetMark() != *aSrchPam.GetPoint() )
                 break; // found
             else if( !pSet->Count() )
@@ -1166,10 +1269,12 @@ int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
         }
 
         std::unique_ptr<OUString> pRepl(bRegExp
-                ? sw::ReplaceBackReferences(*pSearchOpt, &rCursor, nullptr/*FIXME*/)
+                ? sw::ReplaceBackReferences(*pSearchOpt, &rCursor, m_pLayout)
                 : nullptr);
-        m_rCursor.GetDoc()->getIDocumentContentOperations().ReplaceRange(
-            rCursor, pRepl ? *pRepl : pSearchOpt->replaceString, bRegExp);
+        sw::ReplaceImpl(rCursor,
+                pRepl ? *pRepl : pSearchOpt->replaceString, bRegExp,
+                *m_rCursor.GetDoc(), m_pLayout);
+
         m_rCursor.SaveTableBoxContent( rCursor.GetPoint() );
 
         if( bRegExp )
@@ -1193,7 +1298,8 @@ int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
         // they are not in ReplaceSet
         if( !pSet->Count() )
         {
-            rCursor.GetDoc()->getIDocumentContentOperations().InsertItemSet(rCursor, *pReplSet);
+            rCursor.GetDoc()->getIDocumentContentOperations().InsertItemSet(
+                    rCursor, *pReplSet, SetAttrMode::DEFAULT, m_pLayout);
         }
         else
         {
@@ -1214,7 +1320,8 @@ int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
                 pItem = aIter.NextItem();
             }
             aSet.Put( *pReplSet );
-            rCursor.GetDoc()->getIDocumentContentOperations().InsertItemSet(rCursor, aSet);
+            rCursor.GetDoc()->getIDocumentContentOperations().InsertItemSet(
+                    rCursor, aSet, SetAttrMode::DEFAULT, m_pLayout);
         }
 
         return FIND_NO_RING;
@@ -1234,7 +1341,8 @@ sal_uLong SwCursor::FindAttrs( const SfxItemSet& rSet, bool bNoCollections,
                           SwDocPositions nStart, SwDocPositions nEnd,
                           bool& bCancel, FindRanges eFndRngs,
                           const i18nutil::SearchOptions2* pSearchOpt,
-                          const SfxItemSet* pReplSet )
+                          const SfxItemSet* pReplSet,
+                          SwRootFrame const*const pLayout)
 {
     // switch off OLE-notifications
     SwDoc* pDoc = GetDoc();
@@ -1251,7 +1359,7 @@ sal_uLong SwCursor::FindAttrs( const SfxItemSet& rSet, bool bNoCollections,
     }
 
     SwFindParaAttr aSwFindParaAttr( rSet, bNoCollections, pSearchOpt,
-                                    pReplSet, *this );
+                                    pReplSet, *this, pLayout );
 
     sal_uLong nRet = FindAll( aSwFindParaAttr, nStart, nEnd, eFndRngs, bCancel );
     pDoc->SetOle2Link( aLnk );
commit 5e81b966778d82692b4763d892b457186a7f269d
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Dec 10 15:25:37 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Dec 18 17:55:29 2018 +0100

    sw_redlinehide_4b: FindText() adapt the replace part as well
    
    When redlining is enabled, the result will be a delete redline for the
    existing text, and an insert redline for the new text; that much is
    obious (and ReplaceRange can deal with a selection larger than one
    SwTextNode easily, since it mostly adds redlines).
    
    For the case when redlining is disabled, there are 2 options,
    and i don't really know which is preferrable from UX point of view:
    
    One approach is to reuse GetRanges() to ignore delete redlines in
    the replace range; move its declaration to different header.
    
    Another approach is to DeleteAndJoin() the existing delete redlines,
    which is the same as the previous model based Hide mode,
    which calls DeleteRedline() to remove the hidden redlines.
    
    Also change ChgAutoCorrWord() to call DeleteSelImpl() directly.
    
    Change-Id: I5974409d09eb39e04cc0b5dfc20d4db510e1cf58

diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx
index fca0cc4f78f5..a5c8e1acc4d2 100644
--- a/sw/inc/crsrsh.hxx
+++ b/sw/inc/crsrsh.hxx
@@ -43,6 +43,7 @@
 class SfxItemSet;
 class SfxPoolItem;
 class SwContentFrame;
+class SwUnoCursor;
 class SwFormatField;
 class SwTextFormatColl;
 class SwTextINetFormat;
@@ -125,8 +126,19 @@ struct SwContentAtPos
 const int CRSR_POSOLD = 0x01,   // cursor stays at old position
           CRSR_POSCHG = 0x02;   // position changed by the layout
 
+namespace sw {
+
+bool ReplaceImpl(SwPaM & rCursor, OUString const& rReplacement,
+        bool const bRegExp, SwDoc & rDoc, SwRootFrame const*const pLayout);
+
 /// Helperfunction to resolve backward references in regular expressions
-OUString *ReplaceBackReferences( const i18nutil::SearchOptions2& rSearchOpt, SwPaM* pPam );
+OUString *ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
+        SwPaM* pPam, SwRootFrame const* pLayout );
+
+bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges,
+        SwDoc & rDoc, SwPaM const& rDelPam);
+
+} // namespace sw
 
 class SW_DLLPUBLIC SwCursorShell
     : public SwViewShell
diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx
index 0dc56d1e5d3f..f72f9e2856b9 100644
--- a/sw/source/core/crsr/findattr.cxx
+++ b/sw/source/core/crsr/findattr.cxx
@@ -1165,8 +1165,9 @@ int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
             const_cast<SwPaM &>(rRegion).GetRingContainer().merge( m_rCursor.GetRingContainer() );
         }
 
-        std::unique_ptr<OUString> pRepl( bRegExp ?
-                ReplaceBackReferences(*pSearchOpt, &rCursor) : nullptr );
+        std::unique_ptr<OUString> pRepl(bRegExp
+                ? sw::ReplaceBackReferences(*pSearchOpt, &rCursor, nullptr/*FIXME*/)
+                : nullptr);
         m_rCursor.GetDoc()->getIDocumentContentOperations().ReplaceRange(
             rCursor, pRepl ? *pRepl : pSearchOpt->replaceString, bRegExp);
         m_rCursor.SaveTableBoxContent( rCursor.GetPoint() );
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx
index c37df0a1fd69..796eeeeb4454 100644
--- a/sw/source/core/crsr/findtxt.cxx
+++ b/sw/source/core/crsr/findtxt.cxx
@@ -35,11 +35,14 @@
 #include <txtatr.hxx>
 #include <txtfld.hxx>
 #include <txtfrm.hxx>
+#include <rootfrm.hxx>
 #include <swcrsr.hxx>
+#include <redline.hxx>
 #include <doc.hxx>
 #include <IDocumentUndoRedo.hxx>
 #include <IDocumentState.hxx>
 #include <IDocumentDrawModelAccess.hxx>
+#include <IDocumentRedlineAccess.hxx>
 #include <dcontact.hxx>
 #include <pamtyp.hxx>
 #include <ndtxt.hxx>
@@ -939,9 +942,12 @@ int SwFindParaText::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
         }
 
         std::unique_ptr<OUString> pRepl( bRegExp
-                ? ReplaceBackReferences(m_rSearchOpt, &rCursor) : nullptr );
-        bool const bReplaced = m_rCursor.GetDoc()->getIDocumentContentOperations().ReplaceRange(
-            rCursor, pRepl ? *pRepl : m_rSearchOpt.replaceString, bRegExp);
+                ? sw::ReplaceBackReferences(m_rSearchOpt, &rCursor, m_pLayout)
+                : nullptr );
+        bool const bReplaced = sw::ReplaceImpl(rCursor,
+                pRepl ? *pRepl : m_rSearchOpt.replaceString,
+                bRegExp, *m_rCursor.GetDoc(), m_pLayout);
+
         m_rCursor.SaveTableBoxContent( rCursor.GetPoint() );
 
         if( bRegExp )
@@ -1008,22 +1014,115 @@ sal_uLong SwCursor::Find_Text( const i18nutil::SearchOptions2& rSearchOpt, bool
     return nRet;
 }
 
-OUString *ReplaceBackReferences( const i18nutil::SearchOptions2& rSearchOpt, SwPaM* pPam )
+namespace sw {
+
+bool ReplaceImpl(
+        SwPaM & rCursor,
+        OUString const& rReplacement,
+        bool const bRegExp,
+        SwDoc & rDoc,
+        SwRootFrame const*const pLayout)
+{
+    bool bReplaced(true);
+    IDocumentContentOperations & rIDCO(rDoc.getIDocumentContentOperations());
+#if 0
+    // FIXME there's some problem with multiple redlines here on Undo
+    std::vector<std::shared_ptr<SwUnoCursor>> ranges;
+    if (rDoc.getIDocumentRedlineAccess().IsRedlineOn()
+        || !pLayout
+        || !pLayout->IsHideRedlines()
+        || sw::GetRanges(ranges, rDoc, rCursor))
+    {
+        bReplaced = rIDCO.ReplaceRange(rCursor, rReplacement, bRegExp);
+    }
+    else
+    {
+        assert(!ranges.empty());
+        assert(ranges.front()->GetPoint()->nNode == ranges.front()->GetMark()->nNode);
+        bReplaced = rIDCO.ReplaceRange(*ranges.front(), rReplacement, bRegExp);
+        for (auto it = ranges.begin() + 1; it != ranges.end(); ++it)
+        {
+            bReplaced &= rIDCO.DeleteAndJoin(**it);
+        }
+    }
+#else
+    IDocumentRedlineAccess const& rIDRA(rDoc.getIDocumentRedlineAccess());
+    if (pLayout && pLayout->IsHideRedlines()
+        && !rIDRA.IsRedlineOn() // otherwise: ReplaceRange will handle it
+        && (rIDRA.GetRedlineFlags() & RedlineFlags::ShowDelete)) // otherwise: ReplaceRange will DeleteRedline()
+    {
+        SwRedlineTable::size_type tmp;
+        rIDRA.GetRedline(*rCursor.Start(), &tmp);
+        while (tmp < rIDRA.GetRedlineTable().size())
+        {
+            SwRangeRedline const*const pRedline(rIDRA.GetRedlineTable()[tmp]);
+            if (*rCursor.End() <= *pRedline->Start())
+            {
+                break;
+            }
+            if (*pRedline->End() <= *rCursor.Start())
+            {
+                ++tmp;
+                continue;
+            }
+            if (pRedline->GetType() == nsRedlineType_t::REDLINE_DELETE)
+            {
+                assert(*pRedline->Start() != *pRedline->End());
+                // search in hidden layout can't overlap redlines
+                assert(*rCursor.Start() <= *pRedline->Start() && *pRedline->End() <= *rCursor.End());
+                SwPaM pam(*pRedline, nullptr);
+                bReplaced &= rIDCO.DeleteAndJoin(pam);
+            }
+            else
+            {
+                ++tmp;
+            }
+        }
+    }
+    bReplaced &= rIDCO.ReplaceRange(rCursor, rReplacement, bRegExp);
+#endif
+    return bReplaced;
+}
+
+OUString *ReplaceBackReferences(const i18nutil::SearchOptions2& rSearchOpt,
+        SwPaM *const pPam, SwRootFrame const*const pLayout)
 {
     OUString *pRet = nullptr;
     if( pPam && pPam->HasMark() &&
         SearchAlgorithms2::REGEXP == rSearchOpt.AlgorithmType2 )
     {
         const SwContentNode* pTextNode = pPam->GetContentNode();
+        if (!pTextNode || !pTextNode->IsTextNode())
+        {
+            return pRet;
+        }
+        SwTextFrame const*const pFrame(pLayout
+            ? static_cast<SwTextFrame const*>(pTextNode->getLayoutFrame(pLayout))
+            : nullptr);
         const bool bParaEnd = rSearchOpt.searchString == "$" || rSearchOpt.searchString == "^$" || rSearchOpt.searchString == "$^";
-        if ( pTextNode && pTextNode->IsTextNode() && (bParaEnd || pTextNode == pPam->GetContentNode( false )) )
+        if (bParaEnd || (pLayout
+                ? sw::FrameContainsNode(*pFrame, pPam->GetMark()->nNode.GetIndex())
+                : pTextNode == pPam->GetContentNode(false)))
         {
             utl::TextSearch aSText( utl::TextSearch::UpgradeToSearchOptions2( rSearchOpt) );
-            OUString rStr = pTextNode->GetTextNode()->GetText();
-            sal_Int32 nStart = pPam->Start()->nContent.GetIndex();
-            sal_Int32 nEnd = pPam->End()->nContent.GetIndex();
+            OUString rStr = pLayout
+                ? pFrame->GetText()
+                : pTextNode->GetTextNode()->GetText();
+            AmbiguousIndex nStart;
+            AmbiguousIndex nEnd;
+            if (pLayout)
+            {
+                nStart.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->Start()));
+                nEnd.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->End()));
+            }
+            else
+            {
+                nStart.SetModelIndex(pPam->Start()->nContent.GetIndex());
+                nEnd.SetModelIndex(pPam->End()->nContent.GetIndex());
+            }
             SearchResult aResult;
-            if ( bParaEnd || aSText.SearchForward( rStr, &nStart, &nEnd, &aResult ) )
+            if (bParaEnd ||
+                aSText.SearchForward(rStr, &nStart.GetAnyIndex(), &nEnd.GetAnyIndex(), &aResult))
             {
                 if ( bParaEnd )
                 {
@@ -1043,4 +1142,6 @@ OUString *ReplaceBackReferences( const i18nutil::SearchOptions2& rSearchOpt, SwP
     return pRet;
 }
 
+} // namespace sw
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index ad467c57580d..6e34a5d33ddc 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -4062,10 +4062,6 @@ bool DocumentContentOperationsManager::ReplaceRangeImpl( SwPaM& rPam, const OUSt
 
         SwPosition *pStt = aDelPam.Start(),
                    *pEnd = aDelPam.End();
-        OSL_ENSURE( pStt->nNode == pEnd->nNode ||
-                ( pStt->nNode.GetIndex() + 1 == pEnd->nNode.GetIndex() &&
-                    !pEnd->nContent.GetIndex() ),
-                "invalid range: Point and Mark on different nodes" );
         bool bOneNode = pStt->nNode == pEnd->nNode;
 
         // Own Undo?
@@ -4201,6 +4197,11 @@ bool DocumentContentOperationsManager::ReplaceRangeImpl( SwPaM& rPam, const OUSt
         }
         else
         {
+            assert((pStt->nNode == pEnd->nNode ||
+                    ( pStt->nNode.GetIndex() + 1 == pEnd->nNode.GetIndex() &&
+                        !pEnd->nContent.GetIndex() )) &&
+                    "invalid range: Point and Mark on different nodes" );
+
             if( !m_rDoc.getIDocumentRedlineAccess().IsIgnoreRedline() && !m_rDoc.getIDocumentRedlineAccess().GetRedlineTable().empty() )
                 m_rDoc.getIDocumentRedlineAccess().DeleteRedline( aDelPam, true, USHRT_MAX );
 
diff --git a/sw/source/core/edit/acorrect.cxx b/sw/source/core/edit/acorrect.cxx
index e5ca4d63c69b..eaf61bec0451 100644
--- a/sw/source/core/edit/acorrect.cxx
+++ b/sw/source/core/edit/acorrect.cxx
@@ -416,7 +416,7 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
                             *ranges.front(), pFnd->GetLong(), false);
                     for (auto it = ranges.begin() + 1; it != ranges.end(); ++it)
                     {
-                        DeleteSel(**it);
+                        DeleteSelImpl(**it);
                     }
                 }
 
diff --git a/sw/source/core/edit/eddel.cxx b/sw/source/core/edit/eddel.cxx
index 126b5000a923..1a37235190a9 100644
--- a/sw/source/core/edit/eddel.cxx
+++ b/sw/source/core/edit/eddel.cxx
@@ -22,9 +22,11 @@
 #include <doc.hxx>
 #include <IDocumentUndoRedo.hxx>
 #include <IDocumentContentOperations.hxx>
+#include <IDocumentRedlineAccess.hxx>
 #include <editsh.hxx>
 #include <cntfrm.hxx>
 #include <pam.hxx>
+#include <unocrsr.hxx>
 #include <swundo.hxx>
 #include <edimp.hxx>
 #include <IMark.hxx>
@@ -318,7 +320,7 @@ bool SwEditShell::Replace( const OUString& rNewStr, bool bRegExpRplc )
         {
             if( rPaM.HasMark() && *rPaM.GetMark() != *rPaM.GetPoint() )
             {
-                bRet = GetDoc()->getIDocumentContentOperations().ReplaceRange( rPaM, rNewStr, bRegExpRplc )
+                bRet = sw::ReplaceImpl(rPaM, rNewStr, bRegExpRplc, *GetDoc(), GetLayout())
                     || bRet;
                 SaveTableBoxContent( rPaM.GetPoint() );
             }
diff --git a/sw/source/core/inc/acorrect.hxx b/sw/source/core/inc/acorrect.hxx
index 73f63c1ebac8..39bd19e91584 100644
--- a/sw/source/core/inc/acorrect.hxx
+++ b/sw/source/core/inc/acorrect.hxx
@@ -21,14 +21,11 @@
 #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;
@@ -116,13 +113,6 @@ 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: */
diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx
index 0d645ab7dd00..c4d6bf2fce8b 100644
--- a/sw/source/uibase/uiview/viewsrch.cxx
+++ b/sw/source/uibase/uiview/viewsrch.cxx
@@ -309,7 +309,8 @@ void SwView::ExecSearch(SfxRequest& rReq)
                             m_pWrtShell->Push();
                         OUString aReplace( m_pSrchItem->GetReplaceString() );
                         i18nutil::SearchOptions2 aTmp( m_pSrchItem->GetSearchOptions() );
-                        OUString *pBackRef = ReplaceBackReferences( aTmp, m_pWrtShell->GetCursor() );
+                        OUString *pBackRef = sw::ReplaceBackReferences(aTmp,
+                            m_pWrtShell->GetCursor(), m_pWrtShell->GetLayout());
                         if( pBackRef )
                             m_pSrchItem->SetReplaceString( *pBackRef );
                         Replace();
commit 77e67e7cd2baeca13c357fbda4c44a90db23de11
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Dec 4 15:57:47 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Dec 18 17:55:29 2018 +0100

    sw_redlinehide_4b: adapt FindText()
    
    Generally speaking, the find functions should find the strings that are
    visible in the document view.  However, they may also be called from
    SwXTextDocument functions, where they ought to find the strings that are
    actually in the document model.
    
    So concoct some funny helper types and adapt this so it can handle both
    cases; it's not pretty but maybe it even works.
    
    Change-Id: I1917398ff928e922673353e75e8fb724dc042031

diff --git a/sw/inc/swcrsr.hxx b/sw/inc/swcrsr.hxx
index 9267ba0f10a0..c46dbde27b7b 100644
--- a/sw/inc/swcrsr.hxx
+++ b/sw/inc/swcrsr.hxx
@@ -117,7 +117,8 @@ public:
                 SwDocPositions nStart, SwDocPositions nEnde,
                 bool& bCancel,
                 FindRanges,
-                bool bReplace = false );
+                bool bReplace = false,
+                SwRootFrame const*const pLayout = nullptr);
     sal_uLong FindFormat( const SwTextFormatColl& rFormatColl,
                 SwDocPositions nStart, SwDocPositions nEnde,
                 bool& bCancel,
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 286cce30f0cf..1fe8fa72e92f 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -3330,7 +3330,7 @@ sal_uLong SwCursorShell::Find_Text( const i18nutil::SearchOptions2& rSearchOpt,
     m_pTableCursor = nullptr;
     SwCallLink aLk( *this ); // watch Cursor-Moves; call Link if needed
     sal_uLong nRet = m_pCurrentCursor->Find_Text(rSearchOpt, bSearchInNotes, eStart, eEnd,
-                                     bCancel, eRng, bReplace );
+                                     bCancel, eRng, bReplace, GetLayout());
     if( nRet || bCancel )
         UpdateCursor();
     return nRet;
diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx
index cc0dfbeff4b1..0dc56d1e5d3f 100644
--- a/sw/source/core/crsr/findattr.cxx
+++ b/sw/source/core/crsr/findattr.cxx
@@ -1136,7 +1136,7 @@ int SwFindParaAttr::DoFind(SwPaM & rCursor, SwMoveFnCollection const & fnMove,
             // TODO: searching for attributes in Outliner text?!
 
             // continue search in correct section (pTextRegion)
-            if (sw::FindTextImpl(aSrchPam, *pSearchOpt, false/*bSearchInNotes*/, *pSText, fnMove, *pTextRegion, bInReadOnly) &&
+            if (sw::FindTextImpl(aSrchPam, *pSearchOpt, false/*bSearchInNotes*/, *pSText, fnMove, *pTextRegion, bInReadOnly, nullptr/*FIXME*/) &&
                 *aSrchPam.GetMark() != *aSrchPam.GetPoint() )
                 break; // found
             else if( !pSet->Count() )
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx
index b70a2219d0b3..c37df0a1fd69 100644
--- a/sw/source/core/crsr/findtxt.cxx
+++ b/sw/source/core/crsr/findtxt.cxx
@@ -34,6 +34,7 @@
 #include <fmtfld.hxx>
 #include <txtatr.hxx>
 #include <txtfld.hxx>
+#include <txtfrm.hxx>
 #include <swcrsr.hxx>
 #include <doc.hxx>
 #include <IDocumentUndoRedo.hxx>
@@ -53,59 +54,198 @@
 using namespace ::com::sun::star;
 using namespace util;
 
+/// because the Find may be called on the View or the Model, we need an index
+/// afflicted by multiple personality disorder
+struct AmbiguousIndex
+{
+private:
+    sal_Int32 m_value;
+
+#ifndef NDEBUG
+    enum class tags : char { Any, Frame, Model };
+    tags m_tag;
+#endif
+
+public:
+    AmbiguousIndex() : m_value(-1)
+#ifndef NDEBUG
+           , m_tag(tags::Any)
+#endif
+    {}
+    explicit AmbiguousIndex(sal_Int32 const value
+#ifndef NDEBUG
+            , tags const tag
+#endif
+        )   : m_value(value)
+#ifndef NDEBUG
+            , m_tag(tag)
+#endif
+    {}
+
+    sal_Int32 & GetAnyIndex() { return m_value; } ///< for arithmetic
+    sal_Int32 const& GetAnyIndex() const { return m_value; } ///< for arithmetic
+    TextFrameIndex GetFrameIndex() const
+    {
+        assert(m_tag != tags::Model);
+        return TextFrameIndex(m_value);
+    }
+    sal_Int32 GetModelIndex() const
+    {
+        assert(m_tag != tags::Frame);
+        return m_value;
+    }
+    void SetFrameIndex(TextFrameIndex const value)
+    {
+#ifndef NDEBUG
+        m_tag = tags::Frame;
+#endif
+        m_value = sal_Int32(value);
+    }
+    void SetModelIndex(sal_Int32 const value)
+    {
+#ifndef NDEBUG
+        m_tag = tags::Model;
+#endif
+        m_value = value;
+    }
+
+    bool operator ==(AmbiguousIndex const& rOther) const
+    {
+        assert(m_tag == tags::Any || rOther.m_tag == tags::Any || m_tag == rOther.m_tag);
+        return m_value == rOther.m_value;
+    }
+    bool operator <=(AmbiguousIndex const& rOther) const
+    {
+        assert(m_tag == tags::Any || rOther.m_tag == tags::Any || m_tag == rOther.m_tag);
+        return m_value <= rOther.m_value;
+    }
+    bool operator < (AmbiguousIndex const& rOther) const
+    {
+        assert(m_tag == tags::Any || rOther.m_tag == tags::Any || m_tag == rOther.m_tag);
+        return m_value <  rOther.m_value;
+    }
+    AmbiguousIndex operator - (AmbiguousIndex const& rOther) const
+    {
+        assert(m_tag == tags::Any || rOther.m_tag == tags::Any || m_tag == rOther.m_tag);
+        return AmbiguousIndex(m_value - rOther.m_value
+#ifndef NDEBUG
+                , std::max(m_tag, rOther.m_tag)
+#endif
+            );
+    }
+};
+
+class MaybeMergedIter
+{
+    boost::optional<sw::MergedAttrIter> m_oMergedIter;
+    SwTextNode const*const m_pNode;
+    size_t m_HintIndex;
+
+public:
+    MaybeMergedIter(SwTextFrame const*const pFrame, SwTextNode const*const pNode)
+        : m_pNode(pNode)
+        , m_HintIndex(0)
+    {
+        if (pFrame)
+        {
+            m_oMergedIter.emplace(*pFrame);
+        }
+    }
+
+    SwTextAttr const* NextAttr(SwTextNode const*& rpNode)
+    {
+        if (m_oMergedIter)
+        {
+            return m_oMergedIter->NextAttr(&rpNode);
+        }
+        if (SwpHints const*const pHints = m_pNode->GetpSwpHints())
+        {
+            if (m_HintIndex < pHints->Count())
+            {
+                rpNode = m_pNode;
+                return pHints->Get(m_HintIndex++);
+            }
+        }
+        return nullptr;
+    }
+};
+
 static OUString
-lcl_CleanStr(const SwTextNode& rNd, sal_Int32 const nStart, sal_Int32& rEnd,
-             std::vector<sal_Int32> &rArr, bool const bRemoveSoftHyphen, bool const bRemoveCommentAnchors)
+lcl_CleanStr(const SwTextNode& rNd,
+             SwTextFrame const*const pFrame,
+             SwRootFrame const*const pLayout,
+             AmbiguousIndex const nStart, AmbiguousIndex & rEnd,
+             std::vector<AmbiguousIndex> &rArr,
+             bool const bRemoveSoftHyphen, bool const bRemoveCommentAnchors)
 {
-    OUStringBuffer buf(rNd.GetText());
+    OUStringBuffer buf(pLayout ? pFrame->GetText() : rNd.GetText());
     rArr.clear();
 
-    const SwpHints *pHts = rNd.GetpSwpHints();
+    MaybeMergedIter iter(pLayout ? pFrame : nullptr, pLayout ? nullptr : &rNd);
 
-    size_t n = 0;
-    sal_Int32 nSoftHyphen = nStart;
-    sal_Int32 nHintStart = -1;
+    AmbiguousIndex nSoftHyphen = nStart;
+    AmbiguousIndex nHintStart;
     bool bNewHint       = true;
     bool bNewSoftHyphen = true;
-    const sal_Int32 nEnd = rEnd;
-    std::vector<sal_Int32> aReplaced;
+    const AmbiguousIndex nEnd = rEnd;
+    std::vector<AmbiguousIndex> aReplaced;
+    SwTextNode const* pNextHintNode(nullptr);
+    SwTextAttr const* pNextHint(iter.NextAttr(pNextHintNode));
 
     do
     {
         if ( bNewHint )
-            nHintStart = pHts && n < pHts->Count() ?
-                         pHts->Get(n)->GetStart() :
-                         -1;
+        {
+            if (pLayout)
+            {
+                nHintStart.SetFrameIndex(pNextHint
+                        ? pFrame->MapModelToView(pNextHintNode, pNextHint->GetStart())
+                        : TextFrameIndex(-1));
+            }
+            else
+            {
+                nHintStart.SetModelIndex(pNextHint ? pNextHint->GetStart() : -1);
+            }
+        }
 
         if ( bNewSoftHyphen )
         {
-            nSoftHyphen = bRemoveSoftHyphen
-                    ?  rNd.GetText().indexOf(CHAR_SOFTHYPHEN, nSoftHyphen)
-                    : -1;
+            if (pLayout)
+            {
+                nSoftHyphen.SetFrameIndex(TextFrameIndex(bRemoveSoftHyphen
+                    ? pFrame->GetText().indexOf(CHAR_SOFTHYPHEN, nSoftHyphen.GetAnyIndex())
+                    : -1));
+            }
+            else
+            {
+                nSoftHyphen.SetModelIndex(bRemoveSoftHyphen
+                    ? rNd.GetText().indexOf(CHAR_SOFTHYPHEN, nSoftHyphen.GetAnyIndex())
+                    : -1);
+            }
         }
 
         bNewHint       = false;
         bNewSoftHyphen = false;
-        sal_Int32 nStt = 0;
+        AmbiguousIndex nStt;
 
         // Check if next stop is a hint.
-        if ( nHintStart>=0
-            && (-1 == nSoftHyphen || nHintStart < nSoftHyphen)
+        if (0 <= nHintStart.GetAnyIndex()
+            && (-1 == nSoftHyphen.GetAnyIndex() || nHintStart < nSoftHyphen)
             && nHintStart < nEnd )
         {
             nStt = nHintStart;
             bNewHint = true;
         }
         // Check if next stop is a soft hyphen.
-        else if (   -1 != nSoftHyphen
-                 && (-1 == nHintStart || nSoftHyphen < nHintStart)
+        else if (   -1 != nSoftHyphen.GetAnyIndex()
+                 && (-1 == nHintStart.GetAnyIndex() || nSoftHyphen < nHintStart)
                  && nSoftHyphen < nEnd)
         {
             nStt = nSoftHyphen;
             bNewSoftHyphen = true;
         }
         // If nSoftHyphen == nHintStart, the current hint *must* be a hint with an end.
-        else if (-1 != nSoftHyphen && nSoftHyphen == nHintStart)
+        else if (-1 != nSoftHyphen.GetAnyIndex() && nSoftHyphen == nHintStart)
         {
             nStt = nSoftHyphen;
             bNewHint = true;
@@ -114,14 +254,14 @@ lcl_CleanStr(const SwTextNode& rNd, sal_Int32 const nStart, sal_Int32& rEnd,
         else
             break;
 
-        const sal_Int32 nCurrent = nStt - rArr.size();
+        AmbiguousIndex nCurrent(nStt);
+        nCurrent.GetAnyIndex() -= rArr.size();
 
         if ( bNewHint )
         {
-            const SwTextAttr* pHt = pHts->Get(n);
-            if ( pHt->HasDummyChar() && (nStt >= nStart) )
+            if (pNextHint->HasDummyChar() && (nStart <= nStt))
             {
-                switch( pHt->Which() )
+                switch (pNextHint->Which())
                 {
                 case RES_TXTATR_FLYCNT:
                 case RES_TXTATR_FTN:
@@ -138,19 +278,19 @@ lcl_CleanStr(const SwTextNode& rNd, sal_Int32 const nStart, sal_Int32& rEnd,
                         // simply removed if first. If at the end, we keep the
                         // replacement and remove afterwards all at a string's
                         // end (might be normal 0x7f).
-                        const bool bEmpty = pHt->Which() != RES_TXTATR_FIELD
-                            || (static_txtattr_cast<SwTextField const*>(pHt)->GetFormatField().GetField()->ExpandField(true, nullptr).isEmpty());
+                        const bool bEmpty = pNextHint->Which() != RES_TXTATR_FIELD
+                            || (static_txtattr_cast<SwTextField const*>(pNextHint)->GetFormatField().GetField()->ExpandField(true, pLayout).isEmpty());
                         if ( bEmpty && nStart == nCurrent )
                         {
                             rArr.push_back( nCurrent );
-                            --rEnd;
-                            buf.remove(nCurrent, 1);
+                            --rEnd.GetAnyIndex();
+                            buf.remove(nCurrent.GetAnyIndex(), 1);
                         }
                         else
                         {
                             if ( bEmpty )
                                 aReplaced.push_back( nCurrent );
-                            buf[nCurrent] = '\x7f';
+                            buf[nCurrent.GetAnyIndex()] = '\x7f';
                         }
                     }
                     break;
@@ -159,8 +299,8 @@ lcl_CleanStr(const SwTextNode& rNd, sal_Int32 const nStart, sal_Int32& rEnd,
                         if( bRemoveCommentAnchors )
                         {
                             rArr.push_back( nCurrent );
-                            --rEnd;
-                            buf.remove( nCurrent, 1 );
+                            --rEnd.GetAnyIndex();
+                            buf.remove( nCurrent.GetAnyIndex(), 1 );
                         }
                     }
                     break;
@@ -169,69 +309,40 @@ lcl_CleanStr(const SwTextNode& rNd, sal_Int32 const nStart, sal_Int32& rEnd,
                     break;
                 }
             }
-            ++n;
+            pNextHint = iter.NextAttr(pNextHintNode);
         }
 
         if ( bNewSoftHyphen )
         {
             rArr.push_back( nCurrent );
-            --rEnd;
-            buf.remove(nCurrent, 1);
-            ++nSoftHyphen;
+            --rEnd.GetAnyIndex();
+            buf.remove(nCurrent.GetAnyIndex(), 1);
+            ++nSoftHyphen.GetAnyIndex();
         }
     }
     while ( true );
 
-    for( std::vector<sal_Int32>::size_type i = aReplaced.size(); i; )
+    for (auto i = aReplaced.size(); i; )
     {
-        const sal_Int32 nTmp = aReplaced[ --i ];
-        if (nTmp == buf.getLength() - 1)
+        const AmbiguousIndex nTmp = aReplaced[ --i ];
+        if (nTmp.GetAnyIndex() == buf.getLength() - 1)
         {
-            buf.truncate(nTmp);
+            buf.truncate(nTmp.GetAnyIndex());
             rArr.push_back( nTmp );
-            --rEnd;
+            --rEnd.GetAnyIndex();
         }
     }
 
     return buf.makeStringAndClear();
 }
 
-// skip all non SwPostIts inside the array
-static size_t GetPostIt(sal_Int32 aCount,const SwpHints *pHts)
-{
-    size_t aIndex = 0;
-    while (aCount)
-    {
-        for (size_t i = 0; i < pHts->Count(); ++i )
-        {
-            aIndex++;
-            const SwTextAttr* pTextAttr = pHts->Get(i);
-            if ( pTextAttr->Which() == RES_TXTATR_ANNOTATION )
-            {
-                aCount--;
-                if (!aCount)
-                    break;
-            }
-        }
-    }
-    // throw away all following non postits
-    for( size_t i = aIndex; i < pHts->Count(); ++i )
-    {
-        const SwTextAttr* pTextAttr = pHts->Get(i);
-        if ( pTextAttr->Which() == RES_TXTATR_ANNOTATION )
-            break;
-        else
-            aIndex++;
-    }
-    return aIndex;
-}
-
 static bool DoSearch(SwPaM & rSearchPam,
     const i18nutil::SearchOptions2& rSearchOpt, utl::TextSearch& rSText,
     SwMoveFnCollection const & fnMove,
     bool bSrchForward, bool bRegSearch, bool bChkEmptyPara, bool bChkParaEnd,
-    sal_Int32 &nStart, sal_Int32 &nEnd, sal_Int32 nTextLen, SwNode* pNode,
-    SwPaM* pPam);
+    AmbiguousIndex & nStart, AmbiguousIndex & nEnd, AmbiguousIndex nTextLen,
+    SwTextNode const* pNode, SwTextFrame const* pTextFrame,
+    SwRootFrame const* pLayout, SwPaM* pPam);
 
 namespace sw {
 
@@ -239,7 +350,7 @@ bool FindTextImpl(SwPaM & rSearchPam,
         const i18nutil::SearchOptions2& rSearchOpt, bool bSearchInNotes,
         utl::TextSearch& rSText,
         SwMoveFnCollection const & fnMove, const SwPaM & rRegion,
-        bool bInReadOnly)
+        bool bInReadOnly, SwRootFrame const*const pLayout)
 {
     if( rSearchOpt.searchString.isEmpty() )
         return false;
@@ -266,47 +377,95 @@ bool FindTextImpl(SwPaM & rSearchPam,
     aSearchItem.SetBackward(!bSrchForward);
 
     // LanguageType eLastLang = 0;
-    while( nullptr != ( pNode = ::GetNode( *pPam, bFirst, fnMove, bInReadOnly ) ))
+    while (nullptr != (pNode = ::GetNode(*pPam, bFirst, fnMove, bInReadOnly, pLayout)))
     {
         if( pNode->IsTextNode() )
         {
             SwTextNode& rTextNode = *pNode->GetTextNode();
-            sal_Int32 nTextLen = rTextNode.GetText().getLength();
-            sal_Int32 nEnd;
-            if( rNdIdx == pPam->GetMark()->nNode )
-                nEnd = pPam->GetMark()->nContent.GetIndex();
+            SwTextFrame const*const pFrame(pLayout
+                ? static_cast<SwTextFrame const*>(rTextNode.getLayoutFrame(pLayout))
+                : nullptr);
+            assert(!pLayout || pFrame);
+            AmbiguousIndex nTextLen;
+            if (pLayout)
+            {
+                nTextLen.SetFrameIndex(TextFrameIndex(pFrame->GetText().getLength()));
+            }
             else
-                nEnd = bSrchForward ? nTextLen : 0;
-            sal_Int32 nStart = rContentIdx.GetIndex();
+            {
+                nTextLen.SetModelIndex(rTextNode.GetText().getLength());
+            }
+            AmbiguousIndex nEnd;
+            if (pLayout
+                    ? FrameContainsNode(*pFrame, pPam->GetMark()->nNode.GetIndex())
+                    : rNdIdx == pPam->GetMark()->nNode)
+            {
+                if (pLayout)
+                {
+                    nEnd.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->GetMark()));
+                }
+                else
+                {
+                    nEnd.SetModelIndex(pPam->GetMark()->nContent.GetIndex());
+                }
+            }
+            else
+            {
+                if (bSrchForward)
+                {
+                    nEnd = nTextLen;
+                }
+                else
+                {
+                    if (pLayout)
+                    {
+                        nEnd.SetFrameIndex(TextFrameIndex(0));
+                    }
+                    else
+                    {
+                        nEnd.SetModelIndex(0);
+                    }
+                }
+            }
+            AmbiguousIndex nStart;
+            if (pLayout)
+            {
+                nStart.SetFrameIndex(pFrame->MapModelToViewPos(*pPam->GetPoint()));
+            }
+            else
+            {
+                nStart.SetModelIndex(rContentIdx.GetIndex());
+            }
 
             /* #i80135# */
             // if there are SwPostItFields inside our current node text, we
             // split the text into separate pieces and search for text inside
             // the pieces as well as inside the fields
-            const SwpHints *pHts = rTextNode.GetpSwpHints();
+            MaybeMergedIter iter(pLayout ? pFrame : nullptr, pLayout ? nullptr : &rTextNode);
 
             // count PostItFields by looping over all fields
-            sal_Int32 aNumberPostits = 0;
-            sal_Int32 aIgnore = 0;
-            if (pHts && bSearchInNotes)
+            std::vector<std::pair<SwTextAttr const*, AmbiguousIndex>> postits;
+            if (bSearchInNotes)
             {
                 if (!bSrchForward)
                 {
                     std::swap(nStart, nEnd);
                 }
 
-                for( size_t i = 0; i < pHts->Count(); ++i )
+                SwTextNode const* pTemp(nullptr);
+                while (SwTextAttr const*const pTextAttr = iter.NextAttr(pTemp))
                 {
-                    const SwTextAttr* pTextAttr = pHts->Get(i);
                     if ( pTextAttr->Which()==RES_TXTATR_ANNOTATION )
                     {
-                        const sal_Int32 aPos = pTextAttr->GetStart();
-                        if ( (aPos >= nStart) && (aPos <= nEnd) )
-                            aNumberPostits++;
-                        else
+                        AmbiguousIndex aPos;
+                        aPos.SetModelIndex(pTextAttr->GetStart());
+                        if (pLayout)
+                        {
+                            aPos.SetFrameIndex(pFrame->MapModelToView(pTemp, aPos.GetModelIndex()));
+                        }
+                        if ((nStart <= aPos) && (aPos <= nEnd))
                         {
-                            if (bSrchForward)
-                                aIgnore++;
+                            postits.emplace_back(pTextAttr, aPos);
                         }
                     }
                 }
@@ -334,7 +493,9 @@ bool FindTextImpl(SwPaM & rSearchPam,
                     if (SwFrameFormat* pFrameFormat = FindFrameFormat(pObject))
                     {
                         const SwPosition* pPosition = pFrameFormat->GetAnchor().GetContentAnchor();
-                        if (!pPosition || pPosition->nNode.GetIndex() != pNode->GetIndex())
+                        if (!pPosition || (pLayout
+                                ? !FrameContainsNode(*pFrame, pPosition->nNode.GetIndex())
+                                : pPosition->nNode.GetIndex() != pNode->GetIndex()))
                             pObject = nullptr;
                     }
                 }
@@ -369,10 +530,29 @@ bool FindTextImpl(SwPaM & rSearchPam,
                 {
                     // If there are any shapes anchored to this node, search there.
                     SwPaM aPaM(pNode->GetDoc()->GetNodes().GetEndOfContent());
-                    aPaM.GetPoint()->nNode = rTextNode;
-                    aPaM.GetPoint()->nContent.Assign(aPaM.GetPoint()->nNode.GetNode().GetTextNode(), nStart);
+                    if (pLayout)
+                    {
+                        *aPaM.GetPoint() = pFrame->MapViewToModelPos(nStart.GetFrameIndex());
+                    }
+                    else
+                    {
+                        aPaM.GetPoint()->nNode = rTextNode;
+                        aPaM.GetPoint()->nContent.Assign(
+                            aPaM.GetPoint()->nNode.GetNode().GetTextNode(),
+                            nStart.GetModelIndex());
+                    }
                     aPaM.SetMark();
-                    aPaM.GetMark()->nNode = rTextNode.GetIndex() + 1;
+                    if (pLayout)
+                    {
+                        aPaM.GetMark()->nNode = (pFrame->GetMergedPara()
+                                ? *pFrame->GetMergedPara()->pLastNode
+                                : rTextNode)
+                            .GetIndex() + 1;
+                    }
+                    else
+                    {
+                        aPaM.GetMark()->nNode = rTextNode.GetIndex() + 1;
+                    }
                     aPaM.GetMark()->nContent.Assign(aPaM.GetMark()->nNode.GetNode().GetTextNode(), 0);
                     if (pNode->GetDoc()->getIDocumentDrawModelAccess().Search(aPaM, aSearchItem) && pSdrView)
                     {
@@ -396,18 +576,21 @@ bool FindTextImpl(SwPaM & rSearchPam,
                 }
             }
 
-            sal_Int32 aStart = 0;
             // do we need to finish a note?
             if (pPostItMgr && pPostItMgr->HasActiveSidebarWin())
             {
                 if (bSearchInNotes)
                 {
-                    if (bSrchForward)
-                        aStart++;
-                    else
+                    if (!postits.empty())
                     {
-                        if (aNumberPostits)
-                            --aNumberPostits;
+                        if (bSrchForward)
+                        {
+                            postits.erase(postits.begin());
+                        }
+                        else
+                        {
+                            postits.pop_back(); // hope that's the right one?
+                        }
                     }
                     //search inside, finish and put focus back into the doc
                     if (pPostItMgr->FinishSearchReplace(rSearchOpt,bSrchForward))
@@ -422,43 +605,72 @@ bool FindTextImpl(SwPaM & rSearchPam,
                 }
             }
 
-            if (aNumberPostits)
+            if (!postits.empty())
             {
                 // now we have to split
-                sal_Int32 nStartInside = 0;
-                sal_Int32 nEndInside = 0;
-                sal_Int32 aLoop= bSrchForward ? aStart : aNumberPostits;
+                AmbiguousIndex nStartInside;
+                AmbiguousIndex nEndInside;
+                sal_Int32 aLoop = bSrchForward ? 0 : postits.size();
 
-                while ( (aLoop>=0) && (aLoop<=aNumberPostits))
+                while ((0 <= aLoop) && (static_cast<size_t>(aLoop) <= postits.size()))
                 {
                     if (bSrchForward)
                     {
-                        nStartInside = aLoop==0 ? nStart : pHts->Get(GetPostIt(aLoop+aIgnore-1,pHts))->GetStart()+1;
-                        nEndInside = aLoop==aNumberPostits ? nEnd : pHts->Get(GetPostIt(aLoop+aIgnore,pHts))->GetStart();
+                        if (aLoop == 0)
+                        {
+                            nStartInside = nStart;
+                        }
+                        else if (pLayout)
+                        {
+                            nStartInside.SetFrameIndex(postits[aLoop - 1].second.GetFrameIndex() + TextFrameIndex(1));
+                        }
+                        else
+                        {
+                            nStartInside.SetModelIndex(postits[aLoop - 1].second.GetModelIndex() + 1);
+                        }
+                        nEndInside = static_cast<size_t>(aLoop) == postits.size()
+                            ? nEnd
+                            : postits[aLoop].second;
                         nTextLen = nEndInside - nStartInside;
                     }
                     else
                     {
-                        nStartInside =  aLoop==aNumberPostits ? nStart : pHts->Get(GetPostIt(aLoop+aIgnore,pHts))->GetStart();
-                        nEndInside = aLoop==0 ? nEnd : pHts->Get(GetPostIt(aLoop+aIgnore-1,pHts))->GetStart()+1;
+                        nStartInside = static_cast<size_t>(aLoop) == postits.size()
+                            ? nStart
+                            : postits[aLoop].second;
+                        if (aLoop == 0)
+                        {
+                            nEndInside = nEnd;
+                        }
+                        else if (pLayout)
+                        {
+                            nEndInside.SetFrameIndex(postits[aLoop - 1].second.GetFrameIndex() + TextFrameIndex(1));
+                        }
+                        else
+                        {
+                            nEndInside.SetModelIndex(postits[aLoop - 1].second.GetModelIndex() + 1);
+                        }
                         nTextLen = nStartInside - nEndInside;
                     }
                     // search inside the text between a note
                     bFound = DoSearch( rSearchPam,
                                        rSearchOpt, rSText, fnMove, bSrchForward,
                                        bRegSearch, bChkEmptyPara, bChkParaEnd,
-                                       nStartInside, nEndInside, nTextLen, pNode,
+                                       nStartInside, nEndInside, nTextLen,
+                                       pNode->GetTextNode(), pFrame, pLayout,
                                        pPam.get() );
                     if ( bFound )
                         break;
                     else
                     {
                         // we should now be right in front of a note, search inside
-                        if ( (bSrchForward && (GetPostIt(aLoop + aIgnore,pHts) < pHts->Count()) ) || ( !bSrchForward && (aLoop!=0) ))
+                        if (bSrchForward
+                            ? (static_cast<size_t>(aLoop) != postits.size())
+                            : (aLoop != 0))
                         {
-                            const SwTextAttr* pTextAttr = bSrchForward
-                                    ? pHts->Get(GetPostIt(aLoop+aIgnore,pHts))
-                                    : pHts->Get(GetPostIt(aLoop+aIgnore-1,pHts));
+                            const SwTextAttr *const pTextAttr = bSrchForward
+                                ? postits[aLoop].first
+                                : postits[aLoop - 1].first;
                             if (pPostItMgr && pPostItMgr->SearchReplace(
                                     static_txtattr_cast<SwTextField const*>(pTextAttr)->GetFormatField(),rSearchOpt,bSrchForward))
                             {
@@ -477,7 +689,9 @@ bool FindTextImpl(SwPaM & rSearchPam,
                 bFound = DoSearch( rSearchPam,
                                    rSearchOpt, rSText, fnMove, bSrchForward,
                                    bRegSearch, bChkEmptyPara, bChkParaEnd,
-                                   nStart, nEnd, nTextLen, pNode, pPam.get() );
+                                   nStart, nEnd, nTextLen,
+                                   pNode->GetTextNode(), pFrame, pLayout,
+                                   pPam.get() );
             }
             if (bFound)
                 break;
@@ -492,14 +706,14 @@ bool DoSearch(SwPaM & rSearchPam,
         const i18nutil::SearchOptions2& rSearchOpt, utl::TextSearch& rSText,
                       SwMoveFnCollection const & fnMove, bool bSrchForward, bool bRegSearch,
                       bool bChkEmptyPara, bool bChkParaEnd,
-                      sal_Int32 &nStart, sal_Int32 &nEnd, sal_Int32 nTextLen,
-                      SwNode* pNode, SwPaM* pPam)
+        AmbiguousIndex & nStart, AmbiguousIndex & nEnd, AmbiguousIndex const nTextLen,
+        SwTextNode const*const pNode, SwTextFrame const*const pFrame,
+        SwRootFrame const*const pLayout, SwPaM* pPam)
 {
     bool bFound = false;
     SwNodeIndex& rNdIdx = pPam->GetPoint()->nNode;
-    const SwNode* pSttNd = &rNdIdx.GetNode();
     OUString sCleanStr;
-    std::vector<sal_Int32> aFltArr;
+    std::vector<AmbiguousIndex> aFltArr;
     LanguageType eLastLang = LANGUAGE_SYSTEM;
     // if the search string contains a soft hyphen,
     // we don't strip them from the text:
@@ -526,10 +740,10 @@ bool DoSearch(SwPaM & rSearchPam,
     }
 
     if( bSrchForward )
-        sCleanStr = lcl_CleanStr(*pNode->GetTextNode(), nStart, nEnd,
+        sCleanStr = lcl_CleanStr(*pNode, pFrame, pLayout, nStart, nEnd,
                         aFltArr, bRemoveSoftHyphens, bRemoveCommentAnchors);
     else
-        sCleanStr = lcl_CleanStr(*pNode->GetTextNode(), nEnd, nStart,
+        sCleanStr = lcl_CleanStr(*pNode, pFrame, pLayout, nEnd, nStart,
                         aFltArr, bRemoveSoftHyphens, bRemoveCommentAnchors);
 
     std::unique_ptr<SwScriptIterator> pScriptIter;
@@ -538,28 +752,32 @@ bool DoSearch(SwPaM & rSearchPam,
 
     if (SearchAlgorithms2::APPROXIMATE == rSearchOpt.AlgorithmType2)
     {
-        pScriptIter.reset(new SwScriptIterator( sCleanStr, nStart, bSrchForward ));
+        pScriptIter.reset(new SwScriptIterator(sCleanStr, nStart.GetAnyIndex(), bSrchForward));
         nSearchScript = g_pBreakIt->GetRealScriptOfText( rSearchOpt.searchString, 0 );
     }
 
-    const sal_Int32 nStringEnd = nEnd;
+    const AmbiguousIndex nStringEnd = nEnd;
     bool bZeroMatch = false;    // zero-length match, i.e. only $ anchor as regex
     while ( ((bSrchForward && nStart < nStringEnd) ||
-            (! bSrchForward && nStart > nStringEnd)) && !bZeroMatch )
+            (!bSrchForward && nStringEnd < nStart)) && !bZeroMatch )
     {
         // SearchAlgorithms_APPROXIMATE works on a per word base so we have to
         // provide the text searcher with the correct locale, because it uses
         // the break-iterator
         if ( pScriptIter )
         {
-            nEnd = pScriptIter->GetScriptChgPos();
+            nEnd.GetAnyIndex() = pScriptIter->GetScriptChgPos();
             nCurrScript = pScriptIter->GetCurrScript();
             if ( nSearchScript == nCurrScript )
             {
-                const LanguageType eCurrLang =
-                        pNode->GetTextNode()->GetLang( bSrchForward ?
-                                                      nStart :
-                                                      nEnd );
+                const LanguageType eCurrLang = pLayout
+                        ? pFrame->GetLangOfChar(bSrchForward
+                                ? nStart.GetFrameIndex()
+                                : nEnd.GetFrameIndex(),
+                            0, true)
+                        : pNode->GetLang(bSrchForward
+                                ? nStart.GetModelIndex()
+                                : nEnd.GetModelIndex());
 
                 if ( eCurrLang != eLastLang )
                 {
@@ -571,10 +789,10 @@ bool DoSearch(SwPaM & rSearchPam,
             }
             pScriptIter->Next();
         }
-        sal_Int32 nProxyStart = nStart;
-        sal_Int32 nProxyEnd = nEnd;
+        AmbiguousIndex nProxyStart = nStart;
+        AmbiguousIndex nProxyEnd = nEnd;
         if( nSearchScript == nCurrScript &&
-                (rSText.*fnMove.fnSearch)( sCleanStr, &nProxyStart, &nProxyEnd, nullptr ) &&
+                (rSText.*fnMove.fnSearch)( sCleanStr, &nProxyStart.GetAnyIndex(), &nProxyEnd.GetAnyIndex(), nullptr) &&
                 !(bZeroMatch = (nProxyStart == nProxyEnd)))
         {
             nStart = nProxyStart;
@@ -587,27 +805,35 @@ bool DoSearch(SwPaM & rSearchPam,
             if( !aFltArr.empty() )
             {
                 // if backward search, switch positions temporarily
-                if( !bSrchForward ) { std::swap(nStart, nEnd); }
+                if (!bSrchForward) { std::swap(nStart, nEnd); }
 
-                sal_Int32 nNew = nStart;
+                AmbiguousIndex nNew = nStart;
                 for (size_t n = 0; n < aFltArr.size() && aFltArr[ n ] <= nStart; ++n )
                 {
-                    ++nNew;
+                    ++nNew.GetAnyIndex();
                 }
 
                 nStart = nNew;
                 nNew = nEnd;
                 for( size_t n = 0; n < aFltArr.size() && aFltArr[ n ] < nEnd; ++n )
                 {
-                    ++nNew;
+                    ++nNew.GetAnyIndex();
                 }
 
                 nEnd = nNew;
                 // if backward search, switch positions temporarily
                 if( !bSrchForward ) { std::swap(nStart, nEnd); }
             }
-            rSearchPam.GetMark()->nContent = nStart;
-            rSearchPam.GetPoint()->nContent = nEnd;
+            if (pLayout)
+            {
+                *rSearchPam.GetMark() = pFrame->MapViewToModelPos(nStart.GetFrameIndex());
+                *rSearchPam.GetPoint() = pFrame->MapViewToModelPos(nEnd.GetFrameIndex());
+            }
+            else
+            {
+                rSearchPam.GetMark()->nContent = nStart.GetModelIndex();
+                rSearchPam.GetPoint()->nContent = nEnd.GetModelIndex();
+            }
 
             // if backward search, switch point and mark
             if( !bSrchForward )

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list