sw/qa/extras/tiledrendering/tiledrendering.cxx            |   15 ++++++++
 sw/qa/extras/tiledrendering2/data/format-insert-list.docx |binary
 sw/qa/extras/tiledrendering2/tiledrendering2.cxx          |   26 ++++++++++++++
 sw/source/core/doc/extinput.cxx                           |   15 +-------
 4 files changed, 44 insertions(+), 12 deletions(-)

New commits:
commit 9538d547a39581c7ef249fa4fd3dd360b971f2c0
Author:     Jaume Pujantell <jaume.pujant...@collabora.com>
AuthorDate: Tue Oct 8 09:29:51 2024 +0200
Commit:     Jaume Pujantell <jaume.pujant...@collabora.com>
CommitDate: Fri Oct 25 10:53:09 2024 +0200

    cool#6382 lok: sw: text wrong format on inserted text
    
    When inserting text at the beginning of a list item the incorrect
    font is used. It used default style instead of the font applied to
    the item text.
    
    Added a test to avoid this regression, and also modified the test
    testIMEFormattingAtEndOfParagraph to better catch regressions there.
    
    This reverts some changes from:
    lok: IME: preserve formatting when inserting at the end of paragraph
    bf96d1f23e5c12f9263643dfdab94fd1361bb098
    lok: IME: directly copy formatting for inserted text
    d8dbd123bfa7f39489ceb15ac83142635531fd43
    tdf#146728 lok: IME: preset formatting in the new paragraph
    218acb48df79101392c2cc3a030ddb5dcee878c7
    
    Change-Id: I60071e06ff448b2e7c2d5a628a344fbfd15b30af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174657
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Reviewed-by: Jaume Pujantell <jaume.pujant...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174869
    Tested-by: Jenkins

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 77a8e53cc4c0..5fb832b66b29 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -2712,6 +2712,21 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testIMEFormattingAtEndOfParagraph)
 
     // check the content
     CPPUNIT_ASSERT_EQUAL(u"bab"_ustr, 
pShellCursor->GetPoint()->GetNode().GetTextNode()->GetText());
+
+    // check the actual weight format of the text
+    SvxWeightItem aBoldWeightItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT);
+    SfxItemSet aSet(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), 
svl::Items<RES_CHRATR_WEIGHT, RES_CHRATR_WEIGHT>);
+    pShellCursor->GetPoint()->GetNode().GetTextNode()->GetParaAttr(aSet, 0, 1);
+    SfxPoolItem const* pPoolItem = aSet.GetItem(RES_CHRATR_WEIGHT);
+    CPPUNIT_ASSERT(*pPoolItem != aBoldWeightItem); // b not bold
+    aSet.ClearItem();
+    pShellCursor->GetPoint()->GetNode().GetTextNode()->GetParaAttr(aSet, 1, 2);
+    pPoolItem = aSet.GetItem(RES_CHRATR_WEIGHT);
+    CPPUNIT_ASSERT(*pPoolItem == aBoldWeightItem); // a bold
+    aSet.ClearItem();
+    pShellCursor->GetPoint()->GetNode().GetTextNode()->GetParaAttr(aSet, 2, 3);
+    pPoolItem = aSet.GetItem(RES_CHRATR_WEIGHT);
+    CPPUNIT_ASSERT(*pPoolItem != aBoldWeightItem); // b not bold
 }
 
 CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testIMEFormattingAfterHeader)
diff --git a/sw/qa/extras/tiledrendering2/data/format-insert-list.docx 
b/sw/qa/extras/tiledrendering2/data/format-insert-list.docx
new file mode 100644
index 000000000000..636fde813f60
Binary files /dev/null and 
b/sw/qa/extras/tiledrendering2/data/format-insert-list.docx differ
diff --git a/sw/qa/extras/tiledrendering2/tiledrendering2.cxx 
b/sw/qa/extras/tiledrendering2/tiledrendering2.cxx
index fdf8efe8126e..37a13b8750ac 100644
--- a/sw/qa/extras/tiledrendering2/tiledrendering2.cxx
+++ b/sw/qa/extras/tiledrendering2/tiledrendering2.cxx
@@ -15,6 +15,8 @@
 
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <comphelper/lok.hxx>
+#include <editeng/editids.hrc>
+#include <editeng/fontitem.hxx>
 #include <sfx2/viewsh.hxx>
 #include <sfx2/bindings.hxx>
 #include <sfx2/viewfrm.hxx>
@@ -377,6 +379,30 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testSignatureState)
     // i.e. the doc was modified by the time the signature state was 
calculated.
     CPPUNIT_ASSERT_EQUAL(SignatureState::NOTVALIDATED, eState);
 }
+
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testFormatInsertStartList)
+{
+    // Given a document containing a list where the text has a changed font
+    SwXTextDocument* pXTextDocument = createDoc("format-insert-list.docx");
+    CPPUNIT_ASSERT(pXTextDocument);
+    VclPtr<vcl::Window> pDocWindow = pXTextDocument->getDocWindow();
+    SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current());
+    assert(pView);
+
+    // Insert a string at the begining of a list item
+    pDocWindow->PostExtTextInputEvent(VclEventId::ExtTextInput, u"a"_ustr);
+    pDocWindow->PostExtTextInputEvent(VclEventId::EndExtTextInput, u""_ustr);
+    Scheduler::ProcessEventsToIdle();
+
+    // The inserted text should have the same font as the rest
+    std::unique_ptr<SvxFontItem> pFontItem;
+    pView->GetViewFrame().GetBindings().QueryState(SID_ATTR_CHAR_FONT, 
pFontItem);
+    CPPUNIT_ASSERT(pFontItem);
+    CPPUNIT_ASSERT_EQUAL(u"Calibri"_ustr, pFontItem->GetFamilyName());
+    // Without the accompanying fix in place, this test fails with:
+    // - Expected: Calibri
+    // - Actual  : MS Sans Serif
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/extinput.cxx b/sw/source/core/doc/extinput.cxx
index c8563facbd85..7ea91125b876 100644
--- a/sw/source/core/doc/extinput.cxx
+++ b/sw/source/core/doc/extinput.cxx
@@ -107,20 +107,12 @@ SwExtTextInput::~SwExtTextInput()
     }
     else
     {
-        // 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;
+        pTNd->EraseText( rPtPos, nEndCnt - nSttCnt );
 
         if( m_bInsText )
         {
-            rPtPos.SetContent(nSttCnt);
-            rDoc.getIDocumentContentOperations().InsertString( *this, sText, 
SwInsertFlags::EMPTYEXPAND );
+            rDoc.getIDocumentContentOperations().InsertString(*this, sText);
         }
-
-        pTNd->EraseText( rPtPos, nLenghtOfOldString );
     }
     if (!bWasIME)
     {
@@ -202,8 +194,7 @@ void SwExtTextInput::SetInputData( const 
CommandExtTextInputData& rData )
             pTNd->EraseText( aIdx, nEndCnt - nSttCnt );
         }
 
-        // NOHINTEXPAND so we can use correct formatting in destructor when we 
finish composing
-        pTNd->InsertText( rNewStr, aIdx, SwInsertFlags::NOHINTEXPAND );
+        pTNd->InsertText(rNewStr, aIdx);
         if( !HasMark() )
             SetMark();
     }

Reply via email to