sw/source/uibase/utlui/content.cxx |   41 +++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

New commits:
commit d62f03d316fb4c60087fc2af626bbd0b35b98693
Author:     Jim Raykowski <rayk...@gmail.com>
AuthorDate: Sun Sep 19 19:55:06 2021 -0800
Commit:     Jim Raykowski <rayk...@gmail.com>
CommitDate: Wed Sep 22 02:54:46 2021 +0200

    tdf#95378 Writer Navigator: Track hyperlinks
    
    Continued effort for request to highlight corresponding Navigator tree
    items at document cursor position.
    
    Change-Id: I21c6b45308c7de654dbf1f904c30336a6229722c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122338
    Tested-by: Jenkins
    Reviewed-by: Jim Raykowski <rayk...@gmail.com>

diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index 4efaa1b40502..4a0eea209990 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -3391,6 +3391,47 @@ void SwContentTree::UpdateTracking()
         return;
     }
 
+    // hyperlinks
+    if (SwContentAtPos aContentAtPos(IsAttrAtPos::InetAttr);
+            m_pActiveShell->GetContentAtPos(m_pActiveShell->GetCursorDocPos(), 
aContentAtPos) &&
+            !(m_bIsRoot && m_nRootType != ContentTypeId::URLFIELD))
+    {
+        // Because hyperlink item names do not need to be unique, finding the 
corrosponding item
+        // in the tree by name may result in incorrect selection. Find the 
item in the tree by
+        // comparing the SwTextINetFormat pointer at the document cursor 
position to that stored
+        // in the item SwURLFieldContent.
+        // find content type entry
+        std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator());
+        bool bFoundEntry = m_xTreeView->get_iter_first(*xIter);
+        while (bFoundEntry && SwResId(STR_CONTENT_TYPE_URLFIELD) != 
m_xTreeView->get_text(*xIter))
+            bFoundEntry = m_xTreeView->iter_next_sibling(*xIter);
+        if (bFoundEntry)
+        {
+            // assure content type entry is expanded
+            m_xTreeView->expand_row(*xIter);
+            // find content type content entry and select it
+            while (m_xTreeView->iter_next(*xIter) && lcl_IsContent(*xIter, 
*m_xTreeView))
+            {
+                if (aContentAtPos.pFndTextAttr == reinterpret_cast<const 
SwURLFieldContent*>
+                        (m_xTreeView->get_id(*xIter).toInt64())->GetINetAttr())
+                {
+                    // get first selected for comparison
+                    std::unique_ptr<weld::TreeIter> 
xFirstSelected(m_xTreeView->make_iterator());
+                    if (!m_xTreeView->get_selected(xFirstSelected.get()))
+                        xFirstSelected.reset();
+                    if (m_xTreeView->count_selected_rows() != 1 ||
+                            m_xTreeView->iter_compare(*xIter, *xFirstSelected) 
!= 0)
+                    {
+                        // unselect all entries and make found entry visible 
and selected
+                        m_xTreeView->set_cursor(*xIter);
+                        Select();
+                    }
+                    break;
+                }
+            }
+        }
+        return;
+    }
     // fields
     if (SwField* pField = m_pActiveShell->GetCurField(); pField &&
             !(m_bIsRoot && m_nRootType != ContentTypeId::TEXTFIELD))

Reply via email to