diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-01-11 15:45:18 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-01-11 16:47:37 +0000 |
commit | 018beb38848fbd93889f29969f7ca5c68d0ac546 (patch) | |
tree | e8f870e4ea81e71f400e7ebbb26137748206465b /vcl | |
parent | d9d14d0a4c4470de19b81d0df64e8635bb720560 (diff) |
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
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/control/edit.cxx | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx index 5edefc33b59c..e2e17d4ba1a5 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; } |