cui/source/tabpages/autocdlg.cxx                           |   10 ++++--
 editeng/source/misc/acorrcfg.cxx                           |    9 +++--
 editeng/source/misc/swafopt.cxx                            |    1 
 include/editeng/swafopt.hxx                                |    1 
 officecfg/registry/schema/org/openoffice/Office/Writer.xcs |    8 +++++
 sw/qa/extras/uiwriter/uiwriter2.cxx                        |   20 +++++++++----
 sw/source/core/edit/autofmt.cxx                            |    8 +++--
 7 files changed, 43 insertions(+), 14 deletions(-)

New commits:
commit 5bd1efb830400e1394d45f122faf7537e4451f33
Author:     Samuel Mehrbrodt <[email protected]>
AuthorDate: Mon Sep 15 11:02:38 2025 +0200
Commit:     Samuel Mehrbrodt <[email protected]>
CommitDate: Mon Nov 10 08:21:52 2025 +0100

    tdf#168228 Don't replace styles unconditionally
    
    When using Autocorrect->Apply, styles were applied unconditionally.
    
    Add a second checkbox to allow disabling "Apply styles" in that case.
    
    Change-Id: I4891f906b5518f518f3ac3e256e21392ade3f824
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190955
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <[email protected]>

diff --git a/cui/source/tabpages/autocdlg.cxx b/cui/source/tabpages/autocdlg.cxx
index 563fde2dc06a..ebfd0dece4e8 100644
--- a/cui/source/tabpages/autocdlg.cxx
+++ b/cui/source/tabpages/autocdlg.cxx
@@ -520,9 +520,12 @@ bool OfaSwAutoFmtOptionsPage::FillItemSet( SfxItemSet*  )
     bModified |= pOpt->bCreateTable != bCheck;
     pOpt->bCreateTable = bCheck;
 
-    bCheck = m_xCheckLB->get_toggle(REPLACE_STYLES, CBCOL_SECOND) == 
TRISTATE_TRUE;
+    bCheck = m_xCheckLB->get_toggle(REPLACE_STYLES, CBCOL_FIRST) == 
TRISTATE_TRUE;
     bModified |= pOpt->bReplaceStyles != bCheck;
     pOpt->bReplaceStyles = bCheck;
+    bCheck = m_xCheckLB->get_toggle(REPLACE_STYLES, CBCOL_SECOND) == 
TRISTATE_TRUE;
+    bModified |= pOpt->bReplaceStylesByInput != bCheck;
+    pOpt->bReplaceStylesByInput = bCheck;
 
     bCheck = m_xCheckLB->get_toggle(REPLACE_DASHES, CBCOL_FIRST) == 
TRISTATE_TRUE;
     bModified |= pOpt->bChgToEnEmDash != bCheck;
@@ -595,7 +598,7 @@ void OfaSwAutoFmtOptionsPage::Reset( const SfxItemSet* )
     CreateEntry(sBulletsAfterSpace,  CBCOL_SECOND);
     CreateEntry(sBorder,            CBCOL_SECOND);
     CreateEntry(sTable,             CBCOL_SECOND);
-    CreateEntry(sReplaceTemplates,  CBCOL_SECOND);
+    CreateEntry(sReplaceTemplates,  CBCOL_BOTH);
     CreateEntry(sDeleteEmptyPara,   CBCOL_FIRST );
     CreateEntry(sUserStyle,         CBCOL_FIRST );
     CreateEntry(sBullet.replaceFirst("%1", sByInputBulletChar), CBCOL_FIRST);
@@ -625,7 +628,8 @@ void OfaSwAutoFmtOptionsPage::Reset( const SfxItemSet* )
     m_xCheckLB->set_toggle(APPLY_NUMBERING_AFTER_SPACE, 
pOpt->bSetNumRuleAfterSpace ? TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
     m_xCheckLB->set_toggle(INSERT_BORDER, pOpt->bSetBorder ? TRISTATE_TRUE : 
TRISTATE_FALSE, CBCOL_SECOND);
     m_xCheckLB->set_toggle(CREATE_TABLE, pOpt->bCreateTable ? TRISTATE_TRUE : 
TRISTATE_FALSE, CBCOL_SECOND);
-    m_xCheckLB->set_toggle(REPLACE_STYLES, pOpt->bReplaceStyles ? 
TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
+    m_xCheckLB->set_toggle(REPLACE_STYLES, pOpt->bReplaceStyles ? 
TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
+    m_xCheckLB->set_toggle(REPLACE_STYLES, pOpt->bReplaceStylesByInput ? 
TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_SECOND);
     m_xCheckLB->set_toggle(DEL_EMPTY_NODE, pOpt->bDelEmptyNode ? TRISTATE_TRUE 
: TRISTATE_FALSE, CBCOL_FIRST);
     m_xCheckLB->set_toggle(REPLACE_USER_COLL, pOpt->bChgUserColl ? 
TRISTATE_TRUE : TRISTATE_FALSE, CBCOL_FIRST);
     m_xCheckLB->set_toggle(REPLACE_BULLETS, pOpt->bChgEnumNum ? TRISTATE_TRUE 
: TRISTATE_FALSE, CBCOL_FIRST);
diff --git a/editeng/source/misc/acorrcfg.cxx b/editeng/source/misc/acorrcfg.cxx
index 6b634e473c1c..f67c73e0fbf1 100644
--- a/editeng/source/misc/acorrcfg.cxx
+++ b/editeng/source/misc/acorrcfg.cxx
@@ -421,8 +421,9 @@ Sequence<OUString>  SvxSwAutoCorrCfg::GetPropertyNames()
         u"Format/ByInput/ApplyNumbering/SpecialCharacter/FontPitch"_ustr,     
//46
         u"Format/Option/SetDOIAttribute"_ustr,                                
//47
         u"Format/ByInput/ApplyBulletsAfterSpace"_ustr,                        
//48
+        u"Format/Option/ReplaceStyle"_ustr,                                   
//49
     };
-    const int nCount = 49;
+    const int nCount = 50;
     Sequence<OUString> aNames(nCount);
     OUString* pNames = aNames.getArray();
     for(int i = 0; i < nCount; i++)
@@ -511,7 +512,7 @@ void SvxSwAutoCorrCfg::Load(bool bInit)
                 case  27: rSwFlags.bSetNumRule = 
*o3tl::doAccess<bool>(pValues[nProp]); break; // 
"Format/ByInput/ApplyNumbering/Enable",
                 case  28: rSwFlags.bSetBorder = 
*o3tl::doAccess<bool>(pValues[nProp]); break; // 
"Format/ByInput/ChangeToBorders",
                 case  29: rSwFlags.bCreateTable = 
*o3tl::doAccess<bool>(pValues[nProp]); break; // "Format/ByInput/ChangeToTable",
-                case  30: rSwFlags.bReplaceStyles =  
*o3tl::doAccess<bool>(pValues[nProp]); break; // "Format/ByInput/ReplaceStyle",
+                case  30: rSwFlags.bReplaceStylesByInput =  
*o3tl::doAccess<bool>(pValues[nProp]); break; // "Format/ByInput/ReplaceStyle",
                 case  31: rSwFlags.bAFormatByInpDelSpacesAtSttEnd =  
*o3tl::doAccess<bool>(pValues[nProp]); break; // 
"Format/ByInput/DelSpacesAtStartEnd",
                 case  32: rSwFlags.bAFormatByInpDelSpacesBetweenLines = 
*o3tl::doAccess<bool>(pValues[nProp]); break; // 
"Format/ByInput/DelSpacesBetween",
                 case  33: rSwFlags.bAutoCompleteWords = 
*o3tl::doAccess<bool>(pValues[nProp]); break; // "Completion/Enable",
@@ -574,6 +575,7 @@ void SvxSwAutoCorrCfg::Load(bool bInit)
                 break;// 
"Format/ByInput/ApplyNumbering/SpecialCharacter/FontPitch",
                 case   47: rSwFlags.bSetDOIAttr = 
*o3tl::doAccess<bool>(pValues[nProp]); break; // 
"Format/Option/SetDOIAttribute",
                 case 48 : rSwFlags.bSetNumRuleAfterSpace = 
*o3tl::doAccess<bool>(pValues[nProp]); break; // 
"Format/ByInput/ApplyNumberingAfterSpace",
+                case 49 : rSwFlags.bReplaceStyles = 
*o3tl::doAccess<bool>(pValues[nProp]); break; // "Format/Option/ReplaceStyle",
             }
         }
     }
@@ -647,7 +649,7 @@ void SvxSwAutoCorrCfg::ImplCommit()
             // "Format/ByInput/ApplyNumbering/Enable"
          css::uno::Any(rSwFlags.bSetBorder), // 
"Format/ByInput/ChangeToBorders"
          css::uno::Any(rSwFlags.bCreateTable), // 
"Format/ByInput/ChangeToTable"
-         css::uno::Any(rSwFlags.bReplaceStyles),
+         css::uno::Any(rSwFlags.bReplaceStylesByInput),
             // "Format/ByInput/ReplaceStyle"
          css::uno::Any(rSwFlags.bAFormatByInpDelSpacesAtSttEnd),
             // "Format/ByInput/DelSpacesAtStartEnd"
@@ -679,6 +681,7 @@ void SvxSwAutoCorrCfg::ImplCommit()
             // "Format/ByInput/ApplyNumbering/SpecialCharacter/FontPitch"
          css::uno::Any(rSwFlags.bSetDOIAttr),
          css::uno::Any(rSwFlags.bSetNumRuleAfterSpace), // 
"Format/ByInput/ApplyNumberingAfterSpace"
+         css::uno::Any(rSwFlags.bReplaceStyles), // 
"Format/Option/ReplaceStyle"
         });
             // "Format/Option/SetDOIAttribute"
 }
diff --git a/editeng/source/misc/swafopt.cxx b/editeng/source/misc/swafopt.cxx
index f37af302d144..7b1df87aa700 100644
--- a/editeng/source/misc/swafopt.cxx
+++ b/editeng/source/misc/swafopt.cxx
@@ -43,6 +43,7 @@ SvxSwAutoFormatFlags::SvxSwAutoFormatFlags()
 
     bChgUserColl =
     bReplaceStyles =
+    bReplaceStylesByInput =
     bDelEmptyNode =
     bWithRedlining =
     bAutoCmpltEndless =
diff --git a/include/editeng/swafopt.hxx b/include/editeng/swafopt.hxx
index 217cb3dd95f0..a80a34fc072d 100644
--- a/include/editeng/swafopt.hxx
+++ b/include/editeng/swafopt.hxx
@@ -116,6 +116,7 @@ struct EDITENG_DLLPUBLIC SvxSwAutoFormatFlags
     bool bSetBorder : 1;
     bool bCreateTable : 1;
     bool bReplaceStyles : 1;
+    bool bReplaceStylesByInput : 1;
 
     bool bWithRedlining : 1;
 
diff --git a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
index 054e7434e89c..3ce84488d980 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
@@ -4101,6 +4101,14 @@
             </info>
             <value>false</value>
           </prop>
+          <prop oor:name="ReplaceStyle" oor:type="xs:boolean" 
oor:nillable="false">
+            <!-- UIHints: Tools  AutoCorrect/AutoFormat  Options  Apply styles 
-->
+            <info>
+              <desc>Specifies whether styles are automatically assigned.</desc>
+              <label>Apply styles</label>
+            </info>
+            <value>false</value>
+          </prop>
           <prop oor:name="CombineParagraphs" oor:type="xs:boolean" 
oor:nillable="false">
             <!-- UIHints: Tools  AutoCorrect/AutoFormat  Options  Combine 
single line paragraphs if length greater -->
             <info>
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 88ed33a31cd1..2eb1c1156a61 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -14,6 +14,7 @@
 #include <com/sun/star/text/XTextTable.hpp>
 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
 #include <comphelper/propertysequence.hxx>
+#include <officecfg/Office/Writer.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <vcl/scheduler.hxx>
 #include <vcl/settings.hxx>
@@ -388,15 +389,22 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf137318)
 
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf136704)
 {
+    Resetter resetter([]() {
+        std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
+            comphelper::ConfigurationChanges::create());
+        
officecfg::Office::Writer::AutoFunction::Format::ByInput::ReplaceStyle::set(false,
 pBatch);
+        
officecfg::Office::Writer::AutoFunction::Format::Option::ReplaceStyle::set(false,
 pBatch);
+        return pBatch->commit();
+    });
+    std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
+        comphelper::ConfigurationChanges::create());
+    
officecfg::Office::Writer::AutoFunction::Format::ByInput::ReplaceStyle::set(true,
 pBatch);
+    
officecfg::Office::Writer::AutoFunction::Format::Option::ReplaceStyle::set(true,
 pBatch);
+    pBatch->commit();
+
     createSwDoc();
     SwWrtShell* const pWrtShell = getSwDocShell()->GetWrtShell();
     SwAutoCorrect corr(*SvxAutoCorrCfg::Get().GetAutoCorrect());
-    corr.GetSwFlags().bReplaceStyles = true;
-    SvxSwAutoFormatFlags flags(*SwEditShell::GetAutoFormatFlags());
-    comphelper::ScopeGuard const g([=]() { 
SwEditShell::SetAutoFormatFlags(&flags); });
-    flags.bReplaceStyles = true;
-    SwEditShell::SetAutoFormatFlags(&flags);
-
     pWrtShell->Insert(u"test"_ustr);
     const sal_Unicode cIns = ':';
     pWrtShell->AutoCorrect(corr, cIns);
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index c5689473ee29..7e17e9209be7 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -2314,7 +2314,8 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, 
SvxSwAutoFormatFlags aFlags,
     if( m_aFlags.bSetNumRule && !m_aFlags.bAFormatByInput )
         m_aFlags.bSetNumRule = false;
 
-    bool bReplaceStyles = !m_aFlags.bAFormatByInput || m_aFlags.bReplaceStyles;
+    SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect();
+    bool bReplaceStyles = m_aFlags.bAFormatByInput ? 
m_aFlags.bReplaceStylesByInput : m_aFlags.bReplaceStyles;
 
     const SwTextFrame * pNextFrame = nullptr;
     bool bNxtEmpty = false;
@@ -2446,7 +2447,6 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, 
SvxSwAutoFormatFlags aFlags,
                 }
 
                 const OUString& rStr = m_pCurTextFrame->GetText();
-                SvxAutoCorrect* pACorr = 
SvxAutoCorrCfg::Get().GetAutoCorrect();
                 SvxSwAutoFormatFlags& rFlags = pACorr->GetSwFlags();
                 if (rFlags.bChgEnumNum && (rStr == "- " || rStr == "* "))
                 {
@@ -2664,7 +2664,10 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, 
SvxSwAutoFormatFlags aFlags,
                 else if( bReplaceStyles )
                     eStat = nLevel ? TST_IDENT : TST_NEG_IDENT;
                 else
+                {
                     eStat = READ_NEXT_PARA;
+                    BuildText();
+                }
             }
             break;
 
@@ -2931,6 +2934,7 @@ void SwEditShell::SetAutoFormatFlags(SvxSwAutoFormatFlags 
const * pFlags)
     pEditFlags->bSetBorder      = pFlags->bSetBorder;
     pEditFlags->bCreateTable    = pFlags->bCreateTable;
     pEditFlags->bReplaceStyles  = pFlags->bReplaceStyles;
+    pEditFlags->bReplaceStylesByInput = pFlags->bReplaceStylesByInput;
     pEditFlags->bAFormatByInpDelSpacesAtSttEnd =
                                     pFlags->bAFormatByInpDelSpacesAtSttEnd;
     pEditFlags->bAFormatByInpDelSpacesBetweenLines =

Reply via email to