sw/qa/extras/uiwriter/uiwriter2.cxx |   19 +++++++++++++++++++
 sw/source/core/crsr/crsrsh.cxx      |   10 ++++++++++
 2 files changed, 29 insertions(+)

New commits:
commit aff731bd80239ef045f224d3cbd9125c43fe1446
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Jun 9 13:59:58 2023 +0200
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sat Jun 10 17:42:27 2023 +0200

    cool#6580 sw: fix infinite loop when changing document language
    
    If there's a footnote in the document, changing the document langauge
    goes into an infinite loop in FindParentText(), because the selection
    created by ExtendedSelectAll(true) is actually invalid, apparently
    the intention is that only very limited functions may be called while it
    is active.
    
    Don't handle this invalid "very" extended selection like one created by
    ExtendedSelectAll(false).
    
    (regression from commit d81379db730a163c5ff75d4f3a3cddbd7b5eddda)
    
    Change-Id: Icf1032715cf2e0a05bf485039c483440c08bb6bb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152811
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 151a910a0bb0..e30958e5c3a8 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -18,6 +18,10 @@
 #include <vcl/scheduler.hxx>
 #include <vcl/settings.hxx>
 #include <vcl/filter/PDFiumLibrary.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <svx/svxids.hrc>
+#include <view.hxx>
 #include <ndtxt.hxx>
 #include <swdtflvr.hxx>
 #include <wrtsh.hxx>
@@ -175,6 +179,21 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf101534)
     CPPUNIT_ASSERT(aSet.HasItem(RES_LR_SPACE));
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testExtendedSelectAllHang)
+{
+    createSwDoc();
+    SwDoc* const pDoc = getSwDoc();
+    SwWrtShell* const pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    pWrtShell->InsertFootnote("");
+    pWrtShell->StartOfSection();
+    SwView* pView = pDoc->GetDocShell()->GetView();
+    SfxStringItem aLangString(SID_LANGUAGE_STATUS, "Default_Spanish 
(Bolivia)");
+    // this looped
+    pView->GetViewFrame()->GetDispatcher()->ExecuteList(SID_LANGUAGE_STATUS, 
SfxCallMode::SYNCHRON,
+                                                        { &aLangString });
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testRedlineMoveInsertInDelete)
 {
     createSwDoc();
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 15c0dc1a6409..bd6ef9e94507 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -873,6 +873,16 @@ SwNode const* SwCursorShell::ExtendedSelectedAll() const
 typename SwCursorShell::StartsWith SwCursorShell::StartsWith_()
 {
     SwShellCursor const*const pShellCursor = getShellCursor(false);
+    // first, check if this is invalid; ExtendedSelectAll(true) may result in
+    // a) an ordinary selection that is valid
+    // b) a selection that is extended
+    // c) a selection that is invalid and will cause FindParentText to loop
+    SwNode const& rEndOfExtras(GetDoc()->GetNodes().GetEndOfExtras());
+    if (pShellCursor->Start()->nNode.GetIndex() <= rEndOfExtras.GetIndex()
+        && rEndOfExtras.GetIndex() < pShellCursor->End()->nNode.GetIndex())
+    {
+        return StartsWith::None; // *very* extended, no ExtendedSelectedAll 
handling!
+    }
     SwStartNode const*const pStartNode(FindParentText(*pShellCursor));
     if (auto const ret = ::StartsWith(*pStartNode); ret != StartsWith::None)
     {

Reply via email to