editeng/source/editeng/impedit2.cxx |   51 ++++++++++++++++--------------------
 vcl/qt5/QtWidget.cxx                |    4 +-
 2 files changed, 26 insertions(+), 29 deletions(-)

New commits:
commit 63a62abae01e7beb15d1e7cb12c469b42253bf1b
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Apr 30 11:30:12 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Tue Apr 30 17:36:05 2024 +0200

    tdf#160838 qt: Update IM cursor position also on modifier change
    
    In `QtWidget::handleKeyEvent`, move the call to
    
        QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle);
    
    further up, so the cursor update also happens for the code path
    of calling the `SalEvent::KeyModChange` callback and then returning
    early.
    
    This makes fcitx5's keyboard layout indicator show up at the right
    position again when switching layout right after starting Writer
    (s. tdf#160838 comment comment 2), which was no longer the case
    after the new code path had been introduced in
    
        commit 862fdb98ca271b60a831cd5420fd16d5f9c1c747
        Date:   Mon Jul 19 15:17:53 2021 +0200
    
            tdf#143298 Qt5 send SalEvent::KeyModChange events
    
    (Not sure whether it wouldn't even make more sense
    to update *after* processing the key event for the
    case that actual text is typed, as that presumably
    modifies the cursor position, but leave the logic
    otherwise unchanged for now.)
    
    Change-Id: I6e21ae51568eefc8e2ae64109d5596f5e20cc28a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166923
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx
index 996a0a7cc9ce..5c860333793f 100644
--- a/vcl/qt5/QtWidget.cxx
+++ b/vcl/qt5/QtWidget.cxx
@@ -580,6 +580,8 @@ bool QtWidget::handleKeyEvent(QtFrame& rFrame, const 
QWidget& rWidget, QKeyEvent
         return true;
     }
 
+    QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle);
+
     if (nCode == 0 && pEvent->text().isEmpty())
     {
         sal_uInt16 nModCode = GetKeyModCode(pEvent->modifiers());
@@ -669,8 +671,6 @@ bool QtWidget::handleKeyEvent(QtFrame& rFrame, const 
QWidget& rWidget, QKeyEvent
     aEvent.mnCode = nCode;
     aEvent.mnCode |= GetKeyModCode(pEvent->modifiers());
 
-    QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle);
-
     bool bStopProcessingKey;
     if (bIsKeyPressed)
         bStopProcessingKey = rFrame.CallCallback(SalEvent::KeyInput, &aEvent);
commit 691c61146d3d627d24fec336550a0d4933549cda
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Apr 30 09:24:53 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Tue Apr 30 17:35:53 2024 +0200

    tdf#160838 editeng: Report IME cursor pos more reliably
    
    `mpIMEInfos` is set when handling the
    `CommandEventId::StartExtTextInput` command. However,
    the cursor position can also be queried without it
    being set, as seen e.g. at least for the fcitx5 use case
    from tdf#160838 when using the Qt-based VCL plugins.
    
    If no IME Input has happened yet, just use the current
    selection PaM index as the end index.
    
    This makes the fcitx5 language indicator show up at the
    current cursor position when positioned in a comment in
    Writer, the Calc input bar or a Math formula and
    switching the fcitx5 language/keyboard layout using the shortcut
    with the Qt-based VCL plugins.
    
    The correct position had no longer been used after welding,
    i.e. since
    
        commit 69c546e1e7a697217f273baa7c1729ff823efd76
        Date:   Fri Dec 4 16:30:31 2020 +0000
    
            weld annotation window
    
    for Writer comments and since
    
        commit e087e25f05e689091cbf1c4f91b6e93878ac17ec
        Date:   Mon Oct 5 14:19:05 2020 +0100
    
            weld InputBar
    
    for the Calc input bar.
    
    The fact that the indicator shows up at the wrong position
    before typing any character (e.g. opening Writer, then switching the
    keyboard layout right away, as mentioend in tdf#160838
    comment 2) is a different issue and will be addressed
    separately.
    
    Change-Id: Ibe7698e113cbbea7f273cc929d72ca47fb407a20
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166888
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/editeng/source/editeng/impedit2.cxx 
b/editeng/source/editeng/impedit2.cxx
index da4d851b3315..9568e800ee4e 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -477,36 +477,33 @@ bool ImpEditEngine::Command( const CommandEvent& rCEvt, 
EditView* pView )
     }
     else if ( rCEvt.GetCommand() == CommandEventId::CursorPos )
     {
-        if (mpIMEInfos)
-        {
-            EditPaM aPaM( pView->getImpl().GetEditSelection().Max() );
-            tools::Rectangle aR1 = PaMtoEditCursor( aPaM );
+        EditPaM aPaM( pView->getImpl().GetEditSelection().Max() );
+        tools::Rectangle aR1 = PaMtoEditCursor( aPaM );
 
-            sal_Int32 nInputEnd = mpIMEInfos->aPos.GetIndex() + 
mpIMEInfos->nLen;
+        if ( !IsFormatted() )
+            FormatDoc();
 
-            if ( !IsFormatted() )
-                FormatDoc();
-
-            ParaPortion* pParaPortion = GetParaPortions().SafeGetObject( 
GetEditDoc().GetPos( aPaM.GetNode() ) );
-            if (pParaPortion)
-            {
-                sal_Int32 nLine = pParaPortion->GetLines().FindLine( 
aPaM.GetIndex(), true );
-                const EditLine& rLine = pParaPortion->GetLines()[nLine];
-                if ( nInputEnd > rLine.GetEnd() )
-                    nInputEnd = rLine.GetEnd();
-                tools::Rectangle aR2 = PaMtoEditCursor( EditPaM( 
aPaM.GetNode(), nInputEnd ), CursorFlags{ .bEndOfLine = true });
-                tools::Rectangle aRect = pView->getImpl().GetWindowPos( aR1 );
-                auto nExtTextInputWidth = aR2.Left() - aR1.Right();
-                if (EditViewCallbacks* pEditViewCallbacks = 
pView->getEditViewCallbacks())
-                    pEditViewCallbacks->EditViewCursorRect(aRect, 
nExtTextInputWidth);
-                else if (vcl::Window* pWindow = pView->GetWindow())
-                    pWindow->SetCursorRect(&aRect, nExtTextInputWidth);
-            }
-        }
-        else
+        ParaPortion* pParaPortion = GetParaPortions().SafeGetObject( 
GetEditDoc().GetPos( aPaM.GetNode() ) );
+        if (pParaPortion)
         {
-            if (vcl::Window* pWindow = pView->GetWindow())
-              pWindow->SetCursorRect();
+            sal_Int32 nLine = pParaPortion->GetLines().FindLine( 
aPaM.GetIndex(), true );
+            const EditLine& rLine = pParaPortion->GetLines()[nLine];
+
+            sal_Int32 nInputEnd;
+            if (mpIMEInfos)
+                nInputEnd = mpIMEInfos->aPos.GetIndex() + mpIMEInfos->nLen;
+            else
+                nInputEnd = aPaM.GetIndex();
+
+            if ( nInputEnd > rLine.GetEnd() )
+                nInputEnd = rLine.GetEnd();
+            tools::Rectangle aR2 = PaMtoEditCursor( EditPaM( aPaM.GetNode(), 
nInputEnd ), CursorFlags{ .bEndOfLine = true });
+            tools::Rectangle aRect = pView->getImpl().GetWindowPos( aR1 );
+            auto nExtTextInputWidth = aR2.Left() - aR1.Right();
+            if (EditViewCallbacks* pEditViewCallbacks = 
pView->getEditViewCallbacks())
+                pEditViewCallbacks->EditViewCursorRect(aRect, 
nExtTextInputWidth);
+            else if (vcl::Window* pWindow = pView->GetWindow())
+                pWindow->SetCursorRect(&aRect, nExtTextInputWidth);
         }
     }
     else if ( rCEvt.GetCommand() == CommandEventId::SelectionChange )

Reply via email to