sw/qa/extras/uiwriter/uiwriter6.cxx |   53 ++++++++++++++++++++++++++++++++++++
 sw/source/core/crsr/viscrs.cxx      |   27 ++++++++++++++++++
 sw/source/core/inc/txtfrm.hxx       |    2 -
 3 files changed, 81 insertions(+), 1 deletion(-)

New commits:
commit f9b4ee0859676555bad4f6cc2513baf7135c4bdb
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Mon Oct 24 11:17:50 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Nov 1 20:49:12 2022 +0100

    tdf#124603 sw: pressing Up/Down triggers pending spell checking
    
    Modified text wasn't checked until the next edit operation,
    so spelling mistake of the last edited word could go unnoticed.
    Leaving the edited line by pressing Up/Down triggers
    pending spell checking to fix the problem in most cases.
    
    Regression from commit 4c91e94e892943ef5e031d65f6f42864233cb4cd
    "tdf#92036: sw: fix idle spelling loop",
    
    Note: add unit test to tdf#92036, too.
    
    Change-Id: I865eb7b5d8f872421230d457989e24c3b489690d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141728
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit e3ae86a38d6282db0f54d3545015ed22ee868ae5)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141852
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx 
b/sw/qa/extras/uiwriter/uiwriter6.cxx
index 6a341088d8e6..b47da8fb386b 100644
--- a/sw/qa/extras/uiwriter/uiwriter6.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter6.cxx
@@ -43,6 +43,7 @@
 #include <dbmgr.hxx>
 #include <rootfrm.hxx>
 #include <unotxdoc.hxx>
+#include <wrong.hxx>
 
 namespace
 {
@@ -1338,6 +1339,58 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testSpellOnlineParameter)
     CPPUNIT_ASSERT_EQUAL(!bSet, pOpt->IsOnlineSpell());
 }
 
+// missing spelling dictionary on Windows test platform?
+#if !defined(_WIN32)
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf124603)
+{
+    SwDoc* pDoc = createSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    const SwViewOption* pOpt = pWrtShell->GetViewOptions();
+    uno::Sequence<beans::PropertyValue> params
+        = comphelper::InitPropertySequence({ { "Enable", uno::Any(true) } });
+    dispatchCommand(mxComponent, ".uno:SpellOnline", params);
+
+    // Automatic Spell Checking is enabled
+
+    CPPUNIT_ASSERT(pOpt->IsOnlineSpell());
+
+    // Type a correct word
+
+    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pXTextDocument);
+    emulateTyping(*pXTextDocument, u"the ");
+    SwCursorShell* pShell(pDoc->GetEditShell());
+    SwTextNode* pNode = pShell->GetCursor()->GetNode().GetTextNode();
+    // no bad word
+    CPPUNIT_ASSERT_EQUAL(static_cast<SwWrongList*>(nullptr), 
pNode->GetWrong());
+
+    // Create a bad word from the good: "the" -> "thex"
+
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+    emulateTyping(*pXTextDocument, u"x");
+    CPPUNIT_ASSERT(pNode->GetWrong());
+    // tdf#92036 pending spell checking
+    bool bPending = !pNode->GetWrong() || !pNode->GetWrong()->Count();
+    CPPUNIT_ASSERT(bPending);
+
+    // Move right, leave the bad word
+
+    pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+    CPPUNIT_ASSERT(pNode->GetWrong());
+    // tdf#92036 still pending spell checking
+    bPending = !pNode->GetWrong() || !pNode->GetWrong()->Count();
+    CPPUNIT_ASSERT(bPending);
+
+    // Move down to trigger spell checking
+
+    pWrtShell->Down(/*bSelect=*/false, 1);
+    Scheduler::ProcessEventsToIdle();
+    CPPUNIT_ASSERT(pNode->GetWrong());
+    // This was 0 (pending spell checking)
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pNode->GetWrong()->Count());
+}
+#endif
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testRedlineAutoCorrect)
 {
     SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "redline-autocorrect.fodt");
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index 86878ad50c82..9e41acb4abcb 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -1027,6 +1027,33 @@ void SwShellCursor::SaveTableBoxContent( const 
SwPosition* pPos )
 
 bool SwShellCursor::UpDown( bool bUp, sal_uInt16 nCnt )
 {
+    // tdf#124603 trigger pending spell checking of the node
+    if ( nCnt == 1 )
+    {
+        SwTextNode* pNode = GetPoint()->nNode.GetNode().GetTextNode();
+        if( pNode && SwTextNode::WrongState::PENDING == pNode->GetWrongDirty() 
)
+        {
+            SwWrtShell* pShell = pNode->GetDoc().GetDocShell()->GetWrtShell();
+            if ( pShell && !pShell->IsSelection() && !pShell->IsSelFrameMode() 
)
+            {
+                const SwViewOption* pVOpt = pShell->GetViewOptions();
+                if ( pVOpt && pVOpt->IsOnlineSpell() )
+                {
+                    const bool bOldViewLock = pShell->IsViewLocked();
+                    pShell->LockView( true );
+
+                    SwTextFrame* pFrame(
+                        
static_cast<SwTextFrame*>(pNode->getLayoutFrame(GetShell()->GetLayout())));
+                    SwRect aRepaint(pFrame->AutoSpell_(*pNode, 0));
+                    if (aRepaint.HasArea())
+                        pShell->InvalidateWindows(aRepaint);
+
+                    pShell->LockView( bOldViewLock );
+                }
+            }
+        }
+    }
+
     return SwCursor::UpDown( bUp, nCnt,
                             &GetPtPos(), GetShell()->GetUpDownX(),
                             *GetShell()->GetLayout());
diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx
index 1b560e0d2bb3..1ba2c832081d 100644
--- a/sw/source/core/inc/txtfrm.hxx
+++ b/sw/source/core/inc/txtfrm.hxx
@@ -342,7 +342,7 @@ public:
      */
     void Init();
 
-    /// Is called by DoIdleJob_() and ExecSpellPopup()
+    /// Is called by DoIdleJob_(), ExecSpellPopup() and UpDown()
     SwRect AutoSpell_(SwTextNode &, sal_Int32);
 
     /// Is called by DoIdleJob_()

Reply via email to