Blame SOURCES/0001-rhbz-1882616-move-cursor-one-step-at-a-time-in-the-d.patch

2654e0
From 8bfdd84ffcffe19aa6c495a0772e1a5fcb9a5124 Mon Sep 17 00:00:00 2001
2654e0
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
2654e0
Date: Fri, 25 Sep 2020 11:22:03 +0100
2654e0
Subject: [PATCH] rhbz#1882616 move cursor one step at a time in the desired
2654e0
 direction
2654e0
MIME-Version: 1.0
2654e0
Content-Type: text/plain; charset=UTF-8
2654e0
Content-Transfer-Encoding: 8bit
2654e0
2654e0
until we get to the target position. The break iterator operates in graphemes
2654e0
so we can't just move Left/Right the amount of utf-16 we want to move.
2654e0
2654e0
Change-Id: I25d4e9285deae374f85dcaadbf4601bc213a89de
2654e0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103380
2654e0
Tested-by: Jenkins
2654e0
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2654e0
(cherry picked from commit bf858622e543163a23db766912ea6b121f447e6d)
2654e0
---
2654e0
 sw/source/core/edit/editsh.cxx | 40 +++++++++++++++++++++++++++++-----
2654e0
 1 file changed, 35 insertions(+), 5 deletions(-)
2654e0
2654e0
diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx
2654e0
index 8f84ce42ed75..872d92d7afcc 100644
2654e0
--- a/sw/source/core/edit/editsh.cxx
2654e0
+++ b/sw/source/core/edit/editsh.cxx
2654e0
@@ -988,7 +988,8 @@ OUString SwEditShell::DeleteExtTextInput( bool bInsText )
2654e0
 
2654e0
 void SwEditShell::SetExtTextInputData( const CommandExtTextInputData& rData )
2654e0
 {
2654e0
-    const SwPosition& rPos = *GetCursor()->GetPoint();
2654e0
+    SwPaM* pCurrentCursor = GetCursor();
2654e0
+    const SwPosition& rPos = *pCurrentCursor->GetPoint();
2654e0
     SwExtTextInput* pInput = GetDoc()->GetExtTextInput( rPos.nNode.GetNode() );
2654e0
     if( !pInput )
2654e0
         return;
2654e0
@@ -1005,10 +1006,39 @@ void SwEditShell::SetExtTextInputData( const CommandExtTextInputData& rData )
2654e0
     // ugly but works
2654e0
     ShowCursor();
2654e0
     const sal_Int32 nDiff = nNewCursorPos - rPos.nContent.GetIndex();
2654e0
-    if( 0 > nDiff )
2654e0
-        Left( -nDiff, CRSR_SKIP_CHARS );
2654e0
-    else if( 0 < nDiff )
2654e0
-        Right( nDiff, CRSR_SKIP_CHARS );
2654e0
+    if( nDiff != 0)
2654e0
+    {
2654e0
+        bool bLeft = nDiff < 0;
2654e0
+        sal_Int32 nMaxGuard = std::abs(nDiff);
2654e0
+        while (true)
2654e0
+        {
2654e0
+            auto nOldPos = pCurrentCursor->GetPoint()->nContent.GetIndex();
2654e0
+            if (bLeft)
2654e0
+                Left(1, CRSR_SKIP_CHARS);
2654e0
+            else
2654e0
+                Right(1, CRSR_SKIP_CHARS);
2654e0
+            auto nNewPos = pCurrentCursor->GetPoint()->nContent.GetIndex();
2654e0
+
2654e0
+            // expected success
2654e0
+            if (nNewPos == nNewCursorPos)
2654e0
+                break;
2654e0
+
2654e0
+            if (nNewPos == nOldPos)
2654e0
+            {
2654e0
+                // if there was no movement, we have failed for some reason
2654e0
+                SAL_WARN("sw.core", "IM cursor move failed");
2654e0
+                break;
2654e0
+            }
2654e0
+
2654e0
+            if (--nMaxGuard == 0)
2654e0
+            {
2654e0
+                // if it takes more cursor moves than there are utf-16 chars to move past
2654e0
+                // something has probably gone wrong
2654e0
+                SAL_WARN("sw.core", "IM abandoning cursor positioning");
2654e0
+                break;
2654e0
+            }
2654e0
+        }
2654e0
+    }
2654e0
 
2654e0
     SetOverwriteCursor( rData.IsCursorOverwrite() );
2654e0
 
2654e0
-- 
2654e0
2.29.2
2654e0