editeng/inc/editattr.hxx            |    2 ++
 editeng/inc/editdoc.hxx             |    1 +
 editeng/source/editeng/editdoc.cxx  |   13 +++++++++++++
 editeng/source/editeng/impedit3.cxx |    6 +++++-
 4 files changed, 21 insertions(+), 1 deletion(-)

New commits:
commit 9dd58f32e2a3b327f2a82387783d71af09d526bd
Author:     Attila Szűcs <attila.sz...@collabora.com>
AuthorDate: Tue Jan 9 17:45:19 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri Jan 12 11:18:44 2024 +0100

    tdf#154248 Impress: fix color of hyperlink
    
    Added a new FindAttrib method that searches in the attribs
    a bit different.
    The original FindAttrib searches in attribs as if their position
    intervals are closed from both side [Start,End].
    However, the actual attribs array was created using PaMs as positions,
    and these are right-opened intervals [Start,End)
    
    Change-Id: I9a46b6b27ce447366fc20af1b46fd60b5c745359
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161836
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/editeng/inc/editattr.hxx b/editeng/inc/editattr.hxx
index 502a5b084605..62d0a0ab5a70 100644
--- a/editeng/inc/editattr.hxx
+++ b/editeng/inc/editattr.hxx
@@ -101,6 +101,8 @@ public:
 
     bool    IsIn( sal_Int32 nIndex ) const
                 { return ( ( nStart <= nIndex ) && ( nEnd >= nIndex ) ); }
+    bool    IsInLeftClosedRightOpen( sal_Int32 nIndex ) const
+                { return ( ( nStart <= nIndex ) && ( nEnd > nIndex ) ); }
     bool    IsInside( sal_Int32 nIndex ) const
                 { return ( ( nStart < nIndex ) && ( nEnd > nIndex ) ); }
     bool        IsEmpty() const
diff --git a/editeng/inc/editdoc.hxx b/editeng/inc/editdoc.hxx
index e5c3abbef0cf..13969badac36 100644
--- a/editeng/inc/editdoc.hxx
+++ b/editeng/inc/editdoc.hxx
@@ -200,6 +200,7 @@ public:
 
     const EditCharAttrib* FindAttrib( sal_uInt16 nWhich, sal_Int32 nPos ) 
const;
     EditCharAttrib* FindAttrib( sal_uInt16 nWhich, sal_Int32 nPos );
+    EditCharAttrib* FindAttribRightOpen( sal_uInt16 nWhich, sal_Int32 nPos );
     const EditCharAttrib* FindNextAttrib( sal_uInt16 nWhich, sal_Int32 
nFromPos ) const;
     EditCharAttrib* FindEmptyAttrib( sal_uInt16 nWhich, sal_Int32 nPos );
     const EditCharAttrib* FindFeature( sal_Int32 nPos ) const;
diff --git a/editeng/source/editeng/editdoc.cxx 
b/editeng/source/editeng/editdoc.cxx
index 9fff222d9368..38641b95efa4 100644
--- a/editeng/source/editeng/editdoc.cxx
+++ b/editeng/source/editeng/editdoc.cxx
@@ -2869,6 +2869,19 @@ EditCharAttrib* CharAttribList::FindAttrib( sal_uInt16 
nWhich, sal_Int32 nPos )
     return nullptr;
 }
 
+EditCharAttrib* CharAttribList::FindAttribRightOpen( sal_uInt16 nWhich, 
sal_Int32 nPos )
+{
+    AttribsType::reverse_iterator it = std::find_if(aAttribs.rbegin(), 
aAttribs.rend(),
+        [&nWhich, &nPos](AttribsType::value_type& rxAttr) {
+            return rxAttr->Which() == nWhich && 
rxAttr->IsInLeftClosedRightOpen(nPos); });
+    if (it != aAttribs.rend())
+    {
+        EditCharAttrib& rAttr = **it;
+        return &rAttr;
+    }
+    return nullptr;
+}
+
 const EditCharAttrib* CharAttribList::FindNextAttrib( sal_uInt16 nWhich, 
sal_Int32 nFromPos ) const
 {
     assert(nWhich);
diff --git a/editeng/source/editeng/impedit3.cxx 
b/editeng/source/editeng/impedit3.cxx
index 8a6ff9d63e6e..0541dfbc91b9 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -2981,7 +2981,11 @@ void ImpEditEngine::SeekCursor( ContentNode* pNode, 
sal_Int32 nPos, SvxFont& rFo
                     // #i1550# hard color attrib should win over text color 
from field
                     if ( pAttrib->Which() == EE_FEATURE_FIELD )
                     {
-                        EditCharAttrib* pColorAttr = 
pNode->GetCharAttribs().FindAttrib( EE_CHAR_COLOR, nPos );
+                        // These Attribs positions come from PaMs, so their 
interval is right-open and left-closed
+                        // when SeekCursor is called, nPos is incremented by 
1. I do not know why...
+                        // probably designed to be a nEndPos, and like in a 
PaM, it is the position after the actual character.
+                        sal_Int32 nPosActual = nPos > 0 ? nPos - 1 : 0;
+                        EditCharAttrib* pColorAttr = 
pNode->GetCharAttribs().FindAttribRightOpen( EE_CHAR_COLOR, nPosActual );
                         if ( pColorAttr )
                             pColorAttr->SetFont( rFont, pOut );
                     }

Reply via email to