svx/source/tbxctrls/tbunosearchcontrollers.cxx |   20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

New commits:
commit d41053defd59257a13916a096da40db152b4b41e
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Jan 18 13:04:35 2024 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jan 18 17:28:46 2024 +0100

    tdf#158277 sw_redlinehide: fix find bar string
    
    FindTextFieldControl::SetTextToSelected_Impl() uses the XModel to
    retrieve the currently selected text, which naturally includes deleted
    text.
    
    Instead, use view API XTextViewCursor to get the visible selected text.
    
    (regression from commit ae2232366f00e08c1855667cfaf068269ac9af2f)
    
    Change-Id: I302ea90a7407af6e3ae7b62a2f373dccb33b8275
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162245
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 1f540c49e68b28a360ee5c32d60ab1bed3837eec)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162229
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/svx/source/tbxctrls/tbunosearchcontrollers.cxx 
b/svx/source/tbxctrls/tbunosearchcontrollers.cxx
index 8e833167ea12..f8c4436443bc 100644
--- a/svx/source/tbxctrls/tbunosearchcontrollers.cxx
+++ b/svx/source/tbxctrls/tbunosearchcontrollers.cxx
@@ -43,6 +43,7 @@
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/text/XTextRange.hpp>
+#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
 #include <com/sun/star/ui/XUIElement.hpp>
 #include <com/sun/star/util/URL.hpp>
 #include <com/sun/star/util/URLTransformer.hpp>
@@ -243,12 +244,21 @@ void FindTextFieldControl::SetTextToSelected_Impl()
     try
     {
         css::uno::Reference<css::frame::XController> 
xController(m_xFrame->getController(), css::uno::UNO_SET_THROW);
-        css::uno::Reference<css::frame::XModel> 
xModel(xController->getModel(), css::uno::UNO_SET_THROW);
-        css::uno::Reference<css::container::XIndexAccess> 
xIndexAccess(xModel->getCurrentSelection(), css::uno::UNO_QUERY_THROW);
-        if (xIndexAccess->getCount() > 0)
+        uno::Reference<text::XTextViewCursorSupplier> const xTVCS(xController, 
uno::UNO_QUERY);
+        if (xTVCS.is())
         {
-            css::uno::Reference<css::text::XTextRange> 
xTextRange(xIndexAccess->getByIndex(0), css::uno::UNO_QUERY_THROW);
-            aString = xTextRange->getString();
+            uno::Reference<text::XTextViewCursor> const 
xTVC(xTVCS->getViewCursor());
+            aString = xTVC->getString();
+        }
+        else
+        {
+            uno::Reference<frame::XModel> xModel(xController->getModel(), 
uno::UNO_SET_THROW);
+            uno::Reference<container::XIndexAccess> 
xIndexAccess(xModel->getCurrentSelection(), uno::UNO_QUERY_THROW);
+            if (xIndexAccess->getCount() > 0)
+            {
+                uno::Reference<text::XTextRange> 
xTextRange(xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW);
+                aString = xTextRange->getString();
+            }
         }
     }
     catch ( ... )

Reply via email to