sd/source/ui/view/drviews7.cxx |   14 ++++++--------
 sd/source/ui/view/drviewsf.cxx |   35 ++++++++++++++++++++++++++---------
 2 files changed, 32 insertions(+), 17 deletions(-)

New commits:
commit 2608bbd931b4fcbeeb517b8e6afb5a126e41ba72
Author:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
AuthorDate: Mon Jul 8 08:22:33 2019 +0200
Commit:     Pranam Lashkari <lpra...@collabora.com>
CommitDate: Fri Feb 5 09:11:23 2021 +0100

    Related tdf#98575 Allow editing link even when URL field is not selected
    
    When the cursor is directly before or behind the URL field,
    just extend the selection so that the link is editable.
    
    Change-Id: I80afe40a1c40e2a02ec6adb18dbdb27b6e39c7d1
    Reviewed-on: https://gerrit.libreoffice.org/75190
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110054
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/sd/source/ui/view/drviews7.cxx b/sd/source/ui/view/drviews7.cxx
index bff0ceea6f29..bf7e6a426231 100644
--- a/sd/source/ui/view/drviews7.cxx
+++ b/sd/source/ui/view/drviews7.cxx
@@ -1446,16 +1446,14 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
             OutlinerView* pOLV = mpDrawView->GetTextEditOutlinerView();
             if (pOLV)
             {
-                const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
+                const SvxFieldItem* pFieldItem = 
pOLV->GetFieldUnderMousePointer();
+                if (!pFieldItem)
+                    pFieldItem = pOLV->GetFieldAtSelection();
                 if (pFieldItem)
                 {
-                    ESelection aSel = pOLV->GetSelection();
-                    if ( abs( aSel.nEndPos - aSel.nStartPos ) == 1 )
-                    {
-                        const SvxFieldData* pField = pFieldItem->GetField();
-                        if ( dynamic_cast< const SvxURLField *>( pField ) !=  
nullptr )
-                            bDisableEditHyperlink = false;
-                    }
+                    const SvxFieldData* pField = pFieldItem->GetField();
+                    if (dynamic_cast<const SvxURLField*>(pField))
+                        bDisableEditHyperlink = false;
                 }
             }
         }
diff --git a/sd/source/ui/view/drviewsf.cxx b/sd/source/ui/view/drviewsf.cxx
index f9f941e78cf5..24edd1887ad9 100644
--- a/sd/source/ui/view/drviewsf.cxx
+++ b/sd/source/ui/view/drviewsf.cxx
@@ -99,17 +99,34 @@ void DrawViewShell::GetCtrlState(SfxItemSet &rSet)
             const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
             if (pFieldItem)
             {
+                // Make sure the whole field is selected
                 ESelection aSel = pOLV->GetSelection();
-                if ( abs( aSel.nEndPos - aSel.nStartPos ) == 1 )
+                if (aSel.nStartPos == aSel.nEndPos)
                 {
-                    const SvxFieldData* pField = pFieldItem->GetField();
-                    if( auto pUrlField = dynamic_cast< const SvxURLField *>( 
pField ) )
-                    {
-                        aHLinkItem.SetName(pUrlField->GetRepresentation());
-                        aHLinkItem.SetURL(pUrlField->GetURL());
-                        aHLinkItem.SetTargetFrame(pUrlField->GetTargetFrame());
-                        bField = true;
-                    }
+                    aSel.nEndPos++;
+                    pOLV->SetSelection(aSel);
+                }
+            }
+            if (!pFieldItem)
+            {
+                // Cursor probably behind the field - extend selection to 
select the field
+                ESelection aSel = pOLV->GetSelection();
+                if (aSel.nStartPos == aSel.nEndPos)
+                {
+                    aSel.nStartPos--;
+                    pOLV->SetSelection(aSel);
+                    pFieldItem = pOLV->GetFieldAtSelection();
+                }
+            }
+            if (pFieldItem)
+            {
+                const SvxFieldData* pField = pFieldItem->GetField();
+                if( auto pUrlField = dynamic_cast< const SvxURLField *>( 
pField ) )
+                {
+                    aHLinkItem.SetName(pUrlField->GetRepresentation());
+                    aHLinkItem.SetURL(pUrlField->GetURL());
+                    aHLinkItem.SetTargetFrame(pUrlField->GetTargetFrame());
+                    bField = true;
                 }
             }
             if (!bField)
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to