sw/inc/editsh.hxx                   |    2 +-
 sw/qa/extras/uiwriter/uiwriter6.cxx |    3 +++
 sw/source/core/edit/editsh.cxx      |    5 +----
 sw/source/uibase/wrtsh/wrtsh1.cxx   |   10 +++++++---
 4 files changed, 12 insertions(+), 8 deletions(-)

New commits:
commit 906ee7050702e36b7509398cd33fd35597eaf528
Author:     Justin Luth <[email protected]>
AuthorDate: Tue Oct 7 18:07:31 2025 -0400
Commit:     Justin Luth <[email protected]>
CommitDate: Wed Oct 8 13:58:13 2025 +0200

    tdf#165973 sw undo: separate AUTOFORMAT after SPLITNODE
    
    When the user presses RETURN,
    they almost certainly want a new paragraph,
    but there is much less certainty
    that they want the autocorrect.
    
    Since 6.2, these have been a single undo event.
    This patch splits it into two undo items,
    and places the AUTOFORMAT item last,
    so that the first undo restores before the autoformat
    and the second undo removes the new paragraph marker.
    
    It was not NECESSARY to affect SwEditShell::SplitNode,
    but it seemed prudent to move everything to a higher level,
    especially since there was no other time bAutoformat was used.
    
    Change-Id: Ia828e3373608e1e5ecf7792dee2bc04321843d6d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192053
    Reviewed-by: Justin Luth <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index b631a1eb5e4a..a44b9e78eb73 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -210,7 +210,7 @@ public:
        Copy all selections to the document. */
     bool CopySelToDoc( SwDoc& rInsDoc );
 
-    SW_DLLPUBLIC void SplitNode( bool bAutoFormat = false, bool 
bCheckTableStart = true );
+    SW_DLLPUBLIC void SplitNode(bool bCheckTableStart = true);
     SW_DLLPUBLIC bool AppendTextNode();
     void AutoFormatBySplitNode();
 
diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx 
b/sw/qa/extras/uiwriter/uiwriter6.cxx
index e6c94420349e..f2b673a8c84a 100644
--- a/sw/qa/extras/uiwriter/uiwriter6.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter6.cxx
@@ -2295,6 +2295,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf51223)
     CPPUNIT_ASSERT_EQUAL(u"I"_ustr, 
static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
     rUndoManager.Undo();
     CPPUNIT_ASSERT_EQUAL(u"i"_ustr, 
static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
+
+    // tdf#165973: undo should only remove autoformat - a second undo 
necessary to undo split
+    CPPUNIT_ASSERT_EQUAL(2, getParagraphs());
 }
 
 // Unit test for fix inconsistent bookmark behavior around at-char/as-char 
anchored frames
diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx
index 58ea61e5c21d..9a69d60e1565 100644
--- a/sw/source/core/edit/editsh.cxx
+++ b/sw/source/core/edit/editsh.cxx
@@ -179,7 +179,7 @@ void SwEditShell::Overwrite(const OUString &rStr)
     EndAllAction();
 }
 
-void SwEditShell::SplitNode( bool bAutoFormat, bool bCheckTableStart )
+void SwEditShell::SplitNode(bool bCheckTableStart)
 {
     StartAllAction();
     GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr);
@@ -193,9 +193,6 @@ void SwEditShell::SplitNode( bool bAutoFormat, bool 
bCheckTableStart )
 
     GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::EMPTY, nullptr);
 
-    if( bAutoFormat )
-        AutoFormatBySplitNode();
-
     ClearTableBoxContent();
 
     EndAllAction();
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx 
b/sw/source/uibase/wrtsh/wrtsh1.cxx
index d3787d5dcf44..d8ca509844bd 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -584,7 +584,7 @@ bool SwWrtShell::InsertOleObject( const 
svt::EmbeddedObjectRef& xRef, SwFlyFrame
     }
 
     if ( !bStarMath )
-        SwFEShell::SplitNode( false, false );
+        SwFEShell::SplitNode(false);
 
     EnterSelFrameMode();
 
@@ -1110,7 +1110,7 @@ void SwWrtShell::InsertColumnBreak()
     {
         if(HasSelection())
             DelRight();
-        SwFEShell::SplitNode( false, false );
+        SwFEShell::SplitNode(false);
     }
     SetAttrItem(SvxFormatBreakItem(SvxBreak::ColumnBefore, RES_BREAK));
 
@@ -1444,9 +1444,13 @@ void SwWrtShell::SplitNode( bool bAutoFormat )
         bHandled = lcl_FoldedOutlineNodeEndOfParaSplit(this);
 
     if (!bHandled)
-        SwFEShell::SplitNode( bAutoFormat );
+        SwFEShell::SplitNode();
 
     EndUndo(SwUndoId::SPLITNODE);
+
+    // run autoformat after "New Paragraph" undo, so it can be undone 
separately from the newline
+    if (!bHandled && bAutoFormat)
+        AutoFormatBySplitNode();
 }
 
 // Turn on numbering

Reply via email to