sw/source/core/edit/editsh.cxx | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-)
New commits: commit bf858622e543163a23db766912ea6b121f447e6d Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Fri Sep 25 11:22:03 2020 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Sep 25 15:59:59 2020 +0200 rhbz#1882616 move cursor one step at a time in the desired direction until we get to the target position. The break iterator operates in graphemes so we can't just move Left/Right the amount of utf-16 we want to move. Change-Id: I25d4e9285deae374f85dcaadbf4601bc213a89de Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103380 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx index e4f26588d0af..1e16460f49e2 100644 --- a/sw/source/core/edit/editsh.cxx +++ b/sw/source/core/edit/editsh.cxx @@ -983,7 +983,8 @@ OUString SwEditShell::DeleteExtTextInput( bool bInsText ) void SwEditShell::SetExtTextInputData( const CommandExtTextInputData& rData ) { - const SwPosition& rPos = *GetCursor()->GetPoint(); + SwPaM* pCurrentCursor = GetCursor(); + const SwPosition& rPos = *pCurrentCursor->GetPoint(); SwExtTextInput* pInput = GetDoc()->GetExtTextInput( rPos.nNode.GetNode() ); if( !pInput ) return; @@ -1000,10 +1001,39 @@ void SwEditShell::SetExtTextInputData( const CommandExtTextInputData& rData ) // ugly but works ShowCursor(); const sal_Int32 nDiff = nNewCursorPos - rPos.nContent.GetIndex(); - if( 0 > nDiff ) - Left( -nDiff, CRSR_SKIP_CHARS ); - else if( 0 < nDiff ) - Right( nDiff, CRSR_SKIP_CHARS ); + if( nDiff != 0) + { + bool bLeft = nDiff < 0; + sal_Int32 nMaxGuard = std::abs(nDiff); + while (true) + { + auto nOldPos = pCurrentCursor->GetPoint()->nContent.GetIndex(); + if (bLeft) + Left(1, CRSR_SKIP_CHARS); + else + Right(1, CRSR_SKIP_CHARS); + auto nNewPos = pCurrentCursor->GetPoint()->nContent.GetIndex(); + + // expected success + if (nNewPos == nNewCursorPos) + break; + + if (nNewPos == nOldPos) + { + // if there was no movement, we have failed for some reason + SAL_WARN("sw.core", "IM cursor move failed"); + break; + } + + if (--nMaxGuard == 0) + { + // if it takes more cursor moves than there are utf-16 chars to move past + // something has probably gone wrong + SAL_WARN("sw.core", "IM abandoning cursor positioning"); + break; + } + } + } SetOverwriteCursor( rData.IsCursorOverwrite() ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits