[Libreoffice-commits] core.git: vcl/source

Caolán McNamara caolanm at redhat.com
Wed Jan 11 16:48:13 UTC 2017


 vcl/source/control/edit.cxx |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

New commits:
commit 018beb38848fbd93889f29969f7ca5c68d0ac546
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Jan 11 15:45:18 2017 +0000

    don't position cursor inside a utf-16 sequence
    
    seen examining rhbz#1409011
    
    insert three 0x2F940 in insert special character
    
    click on end and press backspace and text was mangled
    clise inside the 3 glyph sequence and press delete/backspace and more mangling
    
    Change-Id: I5898e9272e7a90e8b9dabb0be65f493df7dcbaf9

diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index 5edefc3..e2e17d4 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -1217,7 +1217,7 @@ sal_Int32 Edit::ImplGetCharPos( const Point& rWindowPos ) const
 
     GetCaretPositions( aText, pDX, 0, aText.getLength() );
     long nX = rWindowPos.X() - mnXOffset - ImplGetExtraXOffset();
-    for( sal_Int32 i = 0; i < aText.getLength(); i++ )
+    for (sal_Int32 i = 0; i < aText.getLength(); aText.iterateCodePoints(&i))
     {
         if( (pDX[2*i] >= nX && pDX[2*i+1] <= nX) ||
             (pDX[2*i+1] >= nX && pDX[2*i] <= nX))
@@ -1226,12 +1226,12 @@ sal_Int32 Edit::ImplGetCharPos( const Point& rWindowPos ) const
             if( pDX[2*i] < pDX[2*i+1] )
             {
                 if( nX > (pDX[2*i]+pDX[2*i+1])/2 )
-                    nIndex++;
+                    aText.iterateCodePoints(&nIndex);
             }
             else
             {
                 if( nX < (pDX[2*i]+pDX[2*i+1])/2 )
-                    nIndex++;
+                    aText.iterateCodePoints(&nIndex);
             }
             break;
         }
@@ -1239,8 +1239,11 @@ sal_Int32 Edit::ImplGetCharPos( const Point& rWindowPos ) const
     if( nIndex == EDIT_NOLIMIT )
     {
         nIndex = 0;
+        sal_Int32 nFinalIndex = 0;
         long nDiff = std::abs( pDX[0]-nX );
-        for( sal_Int32 i = 1; i < aText.getLength(); i++ )
+        sal_Int32 i = 0;
+        aText.iterateCodePoints(&i);    //skip the first character
+        while (i < aText.getLength())
         {
             long nNewDiff = std::abs( pDX[2*i]-nX );
 
@@ -1249,8 +1252,12 @@ sal_Int32 Edit::ImplGetCharPos( const Point& rWindowPos ) const
                 nIndex = i;
                 nDiff = nNewDiff;
             }
+
+            nFinalIndex = i;
+
+            aText.iterateCodePoints(&i);
         }
-        if( nIndex == aText.getLength()-1 && std::abs( pDX[2*nIndex+1] - nX ) < nDiff )
+        if (nIndex == nFinalIndex && std::abs( pDX[2*nIndex+1] - nX ) < nDiff)
             nIndex = EDIT_NOLIMIT;
     }
 


More information about the Libreoffice-commits mailing list