sw/qa/extras/uiwriter/uiwriter6.cxx | 52 ++++++++++++++++++++++++++++++++++++ sw/source/core/crsr/viscrs.cxx | 27 ++++++++++++++++++ sw/source/core/inc/txtfrm.hxx | 2 - 3 files changed, 80 insertions(+), 1 deletion(-)
New commits: commit e3ae86a38d6282db0f54d3545015ed22ee868ae5 Author: László Németh <nem...@numbertext.org> AuthorDate: Mon Oct 24 11:17:50 2022 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Tue Oct 25 09:16:15 2022 +0200 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> diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx b/sw/qa/extras/uiwriter/uiwriter6.cxx index 0159c5bf07ed..9f483e8688d5 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 { @@ -1337,6 +1338,57 @@ 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& rXTextDocument = getSwXTextDocument(); + emulateTyping(rXTextDocument, u"the "); + SwCursorShell* pShell(pDoc->GetEditShell()); + SwTextNode* pNode = pShell->GetCursor()->GetPointNode().GetTextNode(); + // no bad word + CPPUNIT_ASSERT_EQUAL(static_cast<SwWrongList*>(nullptr), pNode->GetWrong()); + + // Create a bad word from the good: "the" -> "thex" + + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + emulateTyping(rXTextDocument, 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(SwCursorSkipMode::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 5bcc251e22c7..b112ead80317 100644 --- a/sw/source/core/crsr/viscrs.cxx +++ b/sw/source/core/crsr/viscrs.cxx @@ -1049,6 +1049,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()->GetNode().GetTextNode(); + if( pNode && sw::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 f24d889df35f..3fd73ea2c6ec 100644 --- a/sw/source/core/inc/txtfrm.hxx +++ b/sw/source/core/inc/txtfrm.hxx @@ -344,7 +344,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_()