sw/qa/extras/tiledrendering/tiledrendering.cxx | 71 +++++++++++++++++++++++++ sw/source/core/doc/extinput.cxx | 18 ++---- 2 files changed, 78 insertions(+), 11 deletions(-)
New commits: commit 3a04a6c7711eb87500c6a8714a2a6273a8e216a7 Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Fri Dec 17 13:19:28 2021 +0100 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Mon Jan 24 14:44:59 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 <jenkinscollaboraoff...@gmail.com> Reviewed-by: Ashod Nakashian <a...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128860 diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 9f7eca8b1241..7e06bef647e1 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -120,6 +120,7 @@ public: void testRedlineField(); void testIMESupport(); void testIMEFormattingAtEndOfParagraph(); + void testIMEFormattingAfterHeader(); void testSplitNodeRedlineCallback(); void testDeleteNodeRedlineCallback(); void testVisCursorInvalidation(); @@ -196,6 +197,7 @@ public: CPPUNIT_TEST(testRedlineField); CPPUNIT_TEST(testIMESupport); CPPUNIT_TEST(testIMEFormattingAtEndOfParagraph); + CPPUNIT_TEST(testIMEFormattingAfterHeader); CPPUNIT_TEST(testSplitNodeRedlineCallback); CPPUNIT_TEST(testDeleteNodeRedlineCallback); CPPUNIT_TEST(testVisCursorInvalidation); @@ -2364,6 +2366,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 6c3cf951fa72..b72a78ca6635 100644 --- a/sw/source/core/doc/extinput.cxx +++ b/sw/source/core/doc/extinput.cxx @@ -105,20 +105,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( bInsText ) - { - pDoc->getIDocumentContentOperations().InsertString( *this, sText ); + pDoc->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 ); } @@ -208,8 +205,7 @@ void SwExtTextInput::SetInputData( const CommandExtTextInputData& rData ) pTNd->EraseText( aIdx, nEndCnt - nSttCnt ); } - pTNd->InsertText( rNewStr, aIdx, - SwInsertFlags::EMPTYEXPAND ); + pTNd->InsertText( rNewStr, aIdx, SwInsertFlags::NOHINTEXPAND ); if( !HasMark() ) SetMark(); }