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

New commits:
commit ca9341cf60f3f9350662d30b61f6eadefca24667
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Jun 9 13:59:58 2023 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Jun 9 18:07:19 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/+/152797
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index a09d7b6fb780..6c9714367bf7 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 <wrtsh.hxx>
 #include <IDocumentRedlineAccess.hxx>
@@ -168,6 +172,21 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf101534)
     CPPUNIT_ASSERT_EQUAL(::tools::Long(0), 
aSet.GetItem(RES_MARGIN_TEXTLEFT)->GetTextLeft());
 }
 
+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 325ff54d52cd..9fb43ff2d596 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -895,6 +895,16 @@ 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