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

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