editeng/source/editeng/editview.cxx    |    2 +-
 editeng/source/misc/urlfieldhelper.cxx |    3 ++-
 editeng/source/outliner/outlvw.cxx     |    5 -----
 include/editeng/editview.hxx           |    2 +-
 include/editeng/outliner.hxx           |    4 +---
 sc/source/ui/drawfunc/drtxtob.cxx      |    3 ++-
 sc/source/ui/view/editsh.cxx           |    2 +-
 sd/source/ui/view/drviewsf.cxx         |    3 ++-
 8 files changed, 10 insertions(+), 14 deletions(-)

New commits:
commit 32d0efa9d934ec45f2863a285d250dfc0ab137e8
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Mon Nov 6 16:53:50 2023 -0500
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Wed Nov 15 20:05:38 2023 +0100

    tdf#158031 editeng: rename GetFieldAtCursor
    
    because it doesn't really get the field at the cursor,
    and certainly is not similar to SelectFieldAtCursor.
    
    It first gets the field under the mouse.
    Then, if there is a selection, it gets the selected field,
    else it looks for the field on either side.
    
    There were LOTS of places where it
    probably had not been used properly.
    
    Most of those are gone now, so it is easier
    to rename the function.
    
    Change-Id: I1a64af24092582cf865509d2a474080258edd76c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159022
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Jenkins

diff --git a/editeng/source/editeng/editview.cxx 
b/editeng/source/editeng/editview.cxx
index e1229b6918db..81cc8bf1aa56 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -1424,7 +1424,7 @@ void EditView::SelectFieldAtCursor()
         assert(std::abs(aSel.nStartPos - aSel.nEndPos) == 1);
 }
 
-const SvxFieldData* EditView::GetFieldAtCursor(bool bAlsoCheckBeforeCursor) 
const
+const SvxFieldData* EditView::GetFieldUnderMouseOrInSelectionOrAtCursor(bool 
bAlsoCheckBeforeCursor) const
 {
     const SvxFieldItem* pFieldItem = GetFieldUnderMousePointer();
     if (!pFieldItem)
diff --git a/editeng/source/misc/urlfieldhelper.cxx 
b/editeng/source/misc/urlfieldhelper.cxx
index d60d7be92934..57f2a042c6b5 100644
--- a/editeng/source/misc/urlfieldhelper.cxx
+++ b/editeng/source/misc/urlfieldhelper.cxx
@@ -38,7 +38,8 @@ bool URLFieldHelper::IsCursorAtURLField(const EditView& 
pEditView, bool bAlsoChe
     if (!bIsValidSelection)
         return false;
 
-    const SvxFieldData* pField = 
pEditView.GetFieldAtCursor(bAlsoCheckBeforeCursor);
+    const SvxFieldData* pField
+        = 
pEditView.GetFieldUnderMouseOrInSelectionOrAtCursor(bAlsoCheckBeforeCursor);
     if (dynamic_cast<const SvxURLField*>(pField))
         return true;
 
diff --git a/editeng/source/outliner/outlvw.cxx 
b/editeng/source/outliner/outlvw.cxx
index 2649e865d6d7..136ecd776c26 100644
--- a/editeng/source/outliner/outlvw.cxx
+++ b/editeng/source/outliner/outlvw.cxx
@@ -1345,11 +1345,6 @@ const SvxFieldItem* 
OutlinerView::GetFieldAtSelection(bool bAlsoCheckBeforeCurso
     return pEditView->GetFieldAtSelection(bAlsoCheckBeforeCursor);
 }
 
-const SvxFieldData* OutlinerView::GetFieldAtCursor() const
-{
-    return pEditView->GetFieldAtCursor();
-}
-
 void OutlinerView::SelectFieldAtCursor()
 {
     pEditView->SelectFieldAtCursor();
diff --git a/include/editeng/editview.hxx b/include/editeng/editview.hxx
index b54f6b463e1f..01a0e426c09a 100644
--- a/include/editeng/editview.hxx
+++ b/include/editeng/editview.hxx
@@ -334,7 +334,7 @@ public:
     const SvxFieldItem* GetFieldAtSelection(bool* pIsBeforeCursor) const;
 
     /// return field under mouse, at selection, or immediately after (or 
before) the current cursor
-    const SvxFieldData* GetFieldAtCursor(bool bAlsoCheckBeforeCursor = false) 
const;
+    const SvxFieldData* GetFieldUnderMouseOrInSelectionOrAtCursor(bool 
bAlsoCheckBeforeCursor = false) const;
     /// if no selection, select the field immediately after or before the 
current cursor
     void SelectFieldAtCursor();
     /// Converts position in paragraph to logical position without unfolding 
fields
diff --git a/include/editeng/outliner.hxx b/include/editeng/outliner.hxx
index 4f8d41e21b9b..35860b762037 100644
--- a/include/editeng/outliner.hxx
+++ b/include/editeng/outliner.hxx
@@ -307,9 +307,7 @@ public:
     void                InsertField( const SvxFieldItem& rFld );
     const SvxFieldItem* GetFieldUnderMousePointer() const;
     const SvxFieldItem* GetFieldAtSelection(bool bAlsoCheckBeforeCursor = 
false) const;
-    /// Return the field at the current cursor position or nullptr if no field 
found
-    const SvxFieldData* GetFieldAtCursor() const;
-    /// Select the field at the current cursor position
+    /// if no selection, select the field immediately after or before the 
current cursor
     void SelectFieldAtCursor();
 
     /** enables bullets for the selected paragraphs if the bullets/numbering 
of the first paragraph is off
diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index c48b7772f7e3..9ed398fb9876 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -888,7 +888,7 @@ std::unique_ptr<const SvxFieldData> 
ScEditShell::GetURLField()
     if (!pActiveView)
         return std::unique_ptr<const SvxFieldData>();
 
-    const SvxFieldData* pField = pActiveView->GetFieldAtCursor();
+    const SvxFieldData* pField = 
pActiveView->GetFieldUnderMouseOrInSelectionOrAtCursor();
     if (auto pURLField = dynamic_cast<const SvxURLField*>(pField))
         return pURLField->Clone();
 
commit 33ec38c5333e0c71aa995292fbddc1a237979e32
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Mon Nov 6 17:59:09 2023 -0500
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Wed Nov 15 20:05:23 2023 +0100

    tdf#158031 editeng SID_HYPERLINK_GETLINK: use GetFieldAtSelection
    
    This is just a clean-up commit to eliminate the pointless
    check of a field under the mouse pointer.
    It is up to the caller to make sure that the field is selected
    before calling the GETLINK function.
    
    GETLINK is primarily used to get the link from a field
    for the insert/edit hyperlink dialog.
    
    This function SHOULD NOT check before the cursor for the link,
    or else it will mess up the insert hyperlink if the user
    is inserting one field directly after another one.
    So, my changes here are just following what already existed in sw.
    
    Change-Id: Iaa7699d2e5f2fdf26996aede8b35bd4e18b21b98
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159021
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Jenkins

diff --git a/sc/source/ui/drawfunc/drtxtob.cxx 
b/sc/source/ui/drawfunc/drtxtob.cxx
index 863e97edc46b..78bafa27f63e 100644
--- a/sc/source/ui/drawfunc/drtxtob.cxx
+++ b/sc/source/ui/drawfunc/drtxtob.cxx
@@ -384,7 +384,8 @@ void ScDrawTextObjectBar::GetState( SfxItemSet& rSet )
         if ( pOutView )
         {
             bool bField = false;
-            const SvxFieldData* pField = pOutView->GetFieldAtCursor();
+            const SvxFieldItem* pFieldItem = pOutView->GetFieldAtSelection();
+            const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : 
nullptr;
             if (const SvxURLField* pURLField = dynamic_cast<const 
SvxURLField*>(pField))
             {
                 aHLinkItem.SetName( pURLField->GetRepresentation() );
diff --git a/sd/source/ui/view/drviewsf.cxx b/sd/source/ui/view/drviewsf.cxx
index 7a9d40bfc914..1844d796036d 100644
--- a/sd/source/ui/view/drviewsf.cxx
+++ b/sd/source/ui/view/drviewsf.cxx
@@ -88,7 +88,8 @@ void DrawViewShell::GetCtrlState(SfxItemSet &rSet)
 
         if (pOLV)
         {
-            const SvxFieldData* pField = pOLV->GetFieldAtCursor();
+            const SvxFieldItem* pFieldItem = pOLV->GetFieldAtSelection();
+            const SvxFieldData* pField = pFieldItem ? pFieldItem->GetField() : 
nullptr;
             if( auto pUrlField = dynamic_cast< const SvxURLField *>( pField ) )
             {
                 aHLinkItem.SetName(pUrlField->GetRepresentation());

Reply via email to