editeng/source/editeng/impedit2.cxx |   29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

New commits:
commit d88f288c714b1ea91490a37cb5a7718ada9031a8
Author:     Attila Szűcs <[email protected]>
AuthorDate: Mon Feb 9 08:21:11 2026 +0100
Commit:     Attila Szűcs <[email protected]>
CommitDate: Wed Feb 18 10:23:55 2026 +0100

    tdf#159861 editeng: fix cursor at multiline hyperlinks 2
    
    If there is no more text after the multiline hyperlink, then it
    misscalculated the cursor position by 1 line.
    
    Change-Id: Ia936459d40b5c6f510121c459e461877881c29f2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198959
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Stephan Bergmann <[email protected]>

diff --git a/editeng/source/editeng/impedit2.cxx 
b/editeng/source/editeng/impedit2.cxx
index c043eff94e4a..cdfc57053655 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -3174,7 +3174,8 @@ void ImpEditEngine::IterateLineAreas(const 
IterateLinesAreasFunc& f, IterFlag eO
     const tools::Long nVertLineSpacing = CalcVertLineSpacing(aLineStart);
     const tools::Long nColumnWidth = GetColumnWidth(maPaperSize);
     sal_Int16 nColumn = 0;
-    sal_Int32 nUrlYHack = 0;
+    sal_Int32 nUrlYJump = 0;
+    bool bUrlYSkipLine = false;
     for (sal_Int32 n = 0, nPortions = GetParaPortions().Count(); n < 
nPortions; ++n)
     {
         ParaPortion& rPortion = GetParaPortions().getRef(n);
@@ -3216,17 +3217,21 @@ void ImpEditEngine::IterateLineAreas(const 
IterateLinesAreasFunc& f, IterFlag eO
                 tools::Long nLineHeight = rLine.GetHeight();
                 if (nLine != nLines - 1)
                     nLineHeight += nVertLineSpacing;
-                MoveToNextLine(aLineStart, nLineHeight, nColumn, aOrigin,
-                               &aInfo.nHeightNeededToNotWrap);
+                if (!bUrlYSkipLine)
+                {
+                    MoveToNextLine(aLineStart, nLineHeight, nColumn, aOrigin,
+                                   &aInfo.nHeightNeededToNotWrap);
+                }
+                else
+                    bUrlYSkipLine = false;
 
                 // Position the actual line some lines down,
                 // if the previous line ended with a multiline hyperlink
-                if (nUrlYHack != 0)
+                if (nUrlYJump != 0)
                 {
-                    MoveToNextLine(aLineStart, nUrlYHack, nColumn, aOrigin);
-                    nUrlYHack = 0;
+                    MoveToNextLine(aLineStart, nUrlYJump, nColumn, aOrigin);
+                    nUrlYJump = 0;
                 }
-
                 // Check if this line has a textportion with a multiline 
hyperlink
                 // then the next line should be positioned further away
                 for (sal_Int32 nPortion = rLine.GetStartPortion();
@@ -3236,11 +3241,17 @@ void ImpEditEngine::IterateLineAreas(const 
IterateLinesAreasFunc& f, IterFlag eO
                     if (rTextPortion.GetKind() == PortionKind::FIELD)
                     {
                         ExtraPortionInfo* pExtraInfo = 
rTextPortion.GetExtraInfos();
-                        if (pExtraInfo && pExtraInfo->lineBreaksList.size() > 
2)
+                        if (pExtraInfo && pExtraInfo->lineBreaksList.size() > 
1)
                         {
                             // Use the same size calculation as in 
ImpEditEngine::Paint
                             const sal_uInt16 nMaxAscent(rLine.GetMaxAscent());
-                            nUrlYHack = nMaxAscent * 
(pExtraInfo->lineBreaksList.size() - 2);
+                            nUrlYJump = nMaxAscent * 
(pExtraInfo->lineBreaksList.size() - 1);
+                            // if this is not the end of the line ..
+                            // if some caracters (even a soft-break) follows 
the link
+                            if (nLine + 1 < nLines)
+                            {
+                                bUrlYSkipLine = true;
+                            }
                         }
                     }
                 }

Reply via email to