sw/qa/extras/tiledrendering/tiledrendering.cxx |   71 +++++++++++++++++++++++++
 sw/source/core/doc/extinput.cxx                |   19 ++----
 2 files changed, 79 insertions(+), 11 deletions(-)

New commits:
commit de3db2fdce1ee20db65a0275e987ce32d94f2cfd
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Fri Dec 17 13:19:28 2021 +0100
Commit:     Ashod Nakashian <a...@collabora.com>
CommitDate: Sun Jan 23 16:51:28 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>

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index ab63c0003908..7b02eb66a69e 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -138,6 +138,7 @@ public:
     void testRedlineField();
     void testIMESupport();
     void testIMEFormattingAtEndOfParagraph();
+    void testIMEFormattingAfterHeader();
     void testSplitNodeRedlineCallback();
     void testDeleteNodeRedlineCallback();
     void testVisCursorInvalidation();
@@ -222,6 +223,7 @@ public:
     CPPUNIT_TEST(testRedlineField);
     CPPUNIT_TEST(testIMESupport);
     CPPUNIT_TEST(testIMEFormattingAtEndOfParagraph);
+    CPPUNIT_TEST(testIMEFormattingAfterHeader);
     CPPUNIT_TEST(testSplitNodeRedlineCallback);
     CPPUNIT_TEST(testDeleteNodeRedlineCallback);
     CPPUNIT_TEST(testVisCursorInvalidation);
@@ -2533,6 +2535,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 500f5d157b6c..a9b89ed93b9d 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 );
     }
@@ -208,8 +205,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();
     }

Reply via email to