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

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