sw/qa/extras/tiledrendering/tiledrendering.cxx | 71 +++++++++++++++++++++++++ sw/source/core/doc/extinput.cxx | 19 ++---- 2 files changed, 79 insertions(+), 11 deletions(-)
New commits: commit 218acb48df79101392c2cc3a030ddb5dcee878c7 Author: Szymon Kłos <[email protected]> AuthorDate: Fri Dec 17 13:19:28 2021 +0100 Commit: Szymon Kłos <[email protected]> CommitDate: Sun Jan 23 19:53:58 2022 +0100 tdf#146728 lok: IME: preset formatting in the new paragraph When we wrote something using Heading or Title style and then moved to the next paragraph by pressing enter we should get "Text Body" style in the new line. Do not copy style. Use NOHINTEXPAND when inserting initially so we can use EMPTYEXPAND later - at the end of composing - and use correct styling. followup for: lok: IME: directly copy formatting for inserted text d8dbd123bfa7f39489ceb15ac83142635531fd43 https://cgit.freedesktop.org/libreoffice/core/commit/?id=d8dbd123bfa7f39489ceb15ac83142635531fd43 Change-Id: I55b764068337e125eea3fba641edb6486b2ac9d9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127875 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Ashod Nakashian <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128832 Tested-by: Jenkins Reviewed-by: Szymon Kłos <[email protected]> diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 9a09dc504a0f..cc50ef8e9c83 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -139,6 +139,7 @@ public: void testRedlineField(); void testIMESupport(); void testIMEFormattingAtEndOfParagraph(); + void testIMEFormattingAfterHeader(); void testSplitNodeRedlineCallback(); void testDeleteNodeRedlineCallback(); void testVisCursorInvalidation(); @@ -224,6 +225,7 @@ public: CPPUNIT_TEST(testRedlineField); CPPUNIT_TEST(testIMESupport); CPPUNIT_TEST(testIMEFormattingAtEndOfParagraph); + CPPUNIT_TEST(testIMEFormattingAfterHeader); CPPUNIT_TEST(testSplitNodeRedlineCallback); CPPUNIT_TEST(testDeleteNodeRedlineCallback); CPPUNIT_TEST(testVisCursorInvalidation); @@ -2538,6 +2540,75 @@ void SwTiledRenderingTest::testIMEFormattingAtEndOfParagraph() CPPUNIT_ASSERT_EQUAL(OUString("bab"), pShellCursor->GetPoint()->nNode.GetNode().GetTextNode()->GetText()); } +void SwTiledRenderingTest::testIMEFormattingAfterHeader() +{ + comphelper::LibreOfficeKit::setActive(); + SwXTextDocument* pXTextDocument = createDoc("dummy.fodt"); + VclPtr<vcl::Window> pDocWindow = pXTextDocument->getDocWindow(); + + SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current()); + assert(pView); + + // delete all characters + + comphelper::dispatchCommand(".uno:SelectAll", uno::Sequence<beans::PropertyValue>()); + Scheduler::ProcessEventsToIdle(); + + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DELETE); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DELETE); + + Scheduler::ProcessEventsToIdle(); + + pDocWindow->PostExtTextInputEvent(VclEventId::ExtTextInput, "a"); + pDocWindow->PostExtTextInputEvent(VclEventId::EndExtTextInput, ""); + + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RETURN); + Scheduler::ProcessEventsToIdle(); + + // status: "a\n" + + comphelper::dispatchCommand( + ".uno:StyleApply?Style:string=Heading 2&FamilyName:string=ParagraphStyles", + uno::Sequence<beans::PropertyValue>()); + Scheduler::ProcessEventsToIdle(); + + pDocWindow->PostExtTextInputEvent(VclEventId::ExtTextInput, "b"); + pDocWindow->PostExtTextInputEvent(VclEventId::EndExtTextInput, ""); + + pDocWindow->PostExtTextInputEvent(VclEventId::ExtTextInput, "b"); + pDocWindow->PostExtTextInputEvent(VclEventId::EndExtTextInput, ""); + Scheduler::ProcessEventsToIdle(); + + std::unique_ptr<SfxPoolItem> pItem; + pView->GetViewFrame()->GetBindings().QueryState(SID_ATTR_CHAR_WEIGHT, pItem); + auto pWeightItem = dynamic_cast<SvxWeightItem*>(pItem.get()); + CPPUNIT_ASSERT(pWeightItem); + + CPPUNIT_ASSERT_EQUAL(FontWeight::WEIGHT_BOLD, pWeightItem->GetWeight()); + + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RETURN); + Scheduler::ProcessEventsToIdle(); + + // status: "a\n + // <h2>bb</h2>\n" + + pDocWindow->PostExtTextInputEvent(VclEventId::ExtTextInput, "c"); + pDocWindow->PostExtTextInputEvent(VclEventId::EndExtTextInput, ""); + Scheduler::ProcessEventsToIdle(); + + // status: "a\n + // <h2>bb</h2>\n" + // c" + + pView->GetViewFrame()->GetBindings().QueryState(SID_ATTR_CHAR_WEIGHT, pItem); + auto pWeightItem2 = dynamic_cast<SvxWeightItem*>(pItem.get()); + CPPUNIT_ASSERT(pWeightItem2); + + CPPUNIT_ASSERT_EQUAL(FontWeight::WEIGHT_NORMAL, pWeightItem2->GetWeight()); +} + void SwTiledRenderingTest::testSplitNodeRedlineCallback() { // Load a document. diff --git a/sw/source/core/doc/extinput.cxx b/sw/source/core/doc/extinput.cxx index d366a2f852a2..9a06cc1071a1 100644 --- a/sw/source/core/doc/extinput.cxx +++ b/sw/source/core/doc/extinput.cxx @@ -107,20 +107,17 @@ SwExtTextInput::~SwExtTextInput() } else { - // we need to keep correct formatting - // ie. when we erase first, then we will lost information about format + // 1. Insert text at start position with EMPTYEXPAND to use correct formatting + // ABC<NEW><OLD> + // 2. Then remove old (not tracked) content + // ABC<NEW> sal_Int32 nLenghtOfOldString = nEndCnt - nSttCnt; if( m_bInsText ) - { - rDoc.getIDocumentContentOperations().InsertString( *this, sText ); + rDoc.getIDocumentContentOperations().InsertString( *this, sText, SwInsertFlags::EMPTYEXPAND ); - // Copy formatting to the inserted string - SfxItemSet aSet(pTNd->GetDoc().GetAttrPool(), aCharFormatSetRange); - pTNd->GetParaAttr( aSet, nSttCnt + nLenghtOfOldString, nEndCnt + nLenghtOfOldString ); - pTNd->SetAttr( aSet, nSttCnt, nEndCnt ); - } + rIdx = nEndCnt; pTNd->EraseText( rIdx, nLenghtOfOldString ); } @@ -204,8 +201,8 @@ void SwExtTextInput::SetInputData( const CommandExtTextInputData& rData ) pTNd->EraseText( aIdx, nEndCnt - nSttCnt ); } - pTNd->InsertText( rNewStr, aIdx, - SwInsertFlags::EMPTYEXPAND ); + // NOHINTEXPAND so we can use correct formatting in desctructor when we finish composing + pTNd->InsertText( rNewStr, aIdx, SwInsertFlags::NOHINTEXPAND ); if( !HasMark() ) SetMark(); }
