sd/source/ui/view/drtxtob1.cxx       |   22 ++--------------
 sw/qa/extras/uiwriter/uiwriter11.cxx |   24 +++++++++++++++++
 sw/source/uibase/shells/annotsh.cxx  |   20 ++------------
 sw/source/uibase/shells/drwtxtex.cxx |   20 ++------------
 sw/source/uibase/shells/txtattr.cxx  |   48 -----------------------------------
 5 files changed, 34 insertions(+), 100 deletions(-)

New commits:
commit 8b08d755f202f10242768fc38e7466399baa778c
Author:     Jonathan Clark <[email protected]>
AuthorDate: Tue Feb 3 06:13:45 2026 -0700
Commit:     Jonathan Clark <[email protected]>
CommitDate: Tue Feb 3 17:02:23 2026 +0100

    tdf#165206 Do not change alignment after direction change commands
    
    Previously, the UNO commands to change paragraph direction could also
    affect paragraph alignment in certain situations. For example, a
    left-aligned LTR paragraph would become right-aligned after a switch to
    RTL. This was done in order to smooth over usability rough edges due to
    the lack of native start/end paragraph alignment.
    
    We now support start/end paragraph alignment, and encourage its use by
    default. This extra alignment change is no longer necessary.
    
    Change-Id: I90b96c28e194e37fe0e782c054f6f7efdd4bf739
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198597
    Reviewed-by: Jonathan Clark <[email protected]>
    Tested-by: Jenkins

diff --git a/sd/source/ui/view/drtxtob1.cxx b/sd/source/ui/view/drtxtob1.cxx
index 382bf6e4bc9d..751dca3f76d2 100644
--- a/sd/source/ui/view/drtxtob1.cxx
+++ b/sd/source/ui/view/drtxtob1.cxx
@@ -706,24 +706,10 @@ SET_ADJUST:
             else if ( nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT ||
                       nSlot == SID_ATTR_PARA_RIGHT_TO_LEFT )
             {
-                bool bLeftToRight = nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT;
-
-                SvxAdjust nAdjust = SvxAdjust::ParaStart;
-                if( const SvxAdjustItem* pAdjustItem = 
aEditAttr.GetItemIfSet(EE_PARA_JUST) )
-                    nAdjust = pAdjustItem->GetAdjust();
-
-                if( bLeftToRight )
-                {
-                    aNewAttr.Put( SvxFrameDirectionItem( 
SvxFrameDirection::Horizontal_LR_TB, EE_PARA_WRITINGDIR ) );
-                    if( nAdjust == SvxAdjust::Right )
-                        aNewAttr.Put( SvxAdjustItem( SvxAdjust::Left, 
EE_PARA_JUST ) );
-                }
-                else
-                {
-                    aNewAttr.Put( SvxFrameDirectionItem( 
SvxFrameDirection::Horizontal_RL_TB, EE_PARA_WRITINGDIR ) );
-                    if( nAdjust == SvxAdjust::Left )
-                        aNewAttr.Put( SvxAdjustItem( SvxAdjust::Right, 
EE_PARA_JUST ) );
-                }
+                auto eFrameDirection = (nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT)
+                                           ? 
SvxFrameDirection::Horizontal_LR_TB
+                                           : 
SvxFrameDirection::Horizontal_RL_TB;
+                aNewAttr.Put(SvxFrameDirectionItem{ eFrameDirection, 
EE_PARA_WRITINGDIR });
 
                 // tdf#162120: The paragraph direction has been manually set 
by the user.
                 // Don't automatically adjust the paragraph direction anymore.
diff --git a/sw/qa/extras/uiwriter/uiwriter11.cxx 
b/sw/qa/extras/uiwriter/uiwriter11.cxx
index cdabafaeac85..9da790d04fde 100644
--- a/sw/qa/extras/uiwriter/uiwriter11.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter11.cxx
@@ -597,6 +597,30 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest11, testTdf163194)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest11, 
testTdf165206DirSwitchPreservesAlignment)
+{
+    createSwDoc();
+    SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+    CPPUNIT_ASSERT(pWrtShell);
+
+    dispatchCommand(mxComponent, u".uno:ParaLeftToRight"_ustr, {});
+    dispatchCommand(mxComponent, u".uno:LeftPara"_ustr, {});
+
+    CPPUNIT_ASSERT_EQUAL(short(0),
+                         getProperty<short>(getRun(getParagraph(1), 1), 
u"WritingMode"_ustr));
+    CPPUNIT_ASSERT_EQUAL(short(0),
+                         getProperty<short>(getRun(getParagraph(1), 1), 
u"ParaAdjust"_ustr));
+
+    // Explicitly set the direction to RTL.
+    // Previously, this would have also set ParaAdjust to force right.
+    dispatchCommand(mxComponent, u".uno:ParaRightToLeft"_ustr, {});
+
+    CPPUNIT_ASSERT_EQUAL(short(1),
+                         getProperty<short>(getRun(getParagraph(1), 1), 
u"WritingMode"_ustr));
+    CPPUNIT_ASSERT_EQUAL(short(0),
+                         getProperty<short>(getRun(getParagraph(1), 1), 
u"ParaAdjust"_ustr));
+}
+
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/uibase/shells/annotsh.cxx 
b/sw/source/uibase/shells/annotsh.cxx
index b3da5d3aeddb..36c181d2fdb4 100644
--- a/sw/source/uibase/shells/annotsh.cxx
+++ b/sw/source/uibase/shells/annotsh.cxx
@@ -605,25 +605,11 @@ void SwAnnotationShell::Exec( SfxRequest &rReq )
             }
             SfxItemSet aAttr(SfxItemSet::makeFixedSfxItemSet<
                 EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
-                EE_PARA_JUST, EE_PARA_JUST,
                 EE_PARA_AUTOWRITINGDIR, 
EE_PARA_AUTOWRITINGDIR>(*aNewAttr.GetPool()));
 
-            SvxAdjust nAdjust = SvxAdjust::Left;
-            if( const SvxAdjustItem* pAdjustItem = 
aEditAttr.GetItemIfSet(EE_PARA_JUST ) )
-                nAdjust = pAdjustItem->GetAdjust();
-
-            if( bLeftToRight )
-            {
-                aAttr.Put( SvxFrameDirectionItem( 
SvxFrameDirection::Horizontal_LR_TB, EE_PARA_WRITINGDIR ) );
-                if( nAdjust == SvxAdjust::Right )
-                    aAttr.Put( SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ) 
);
-            }
-            else
-            {
-                aAttr.Put( SvxFrameDirectionItem( 
SvxFrameDirection::Horizontal_RL_TB, EE_PARA_WRITINGDIR ) );
-                if( nAdjust == SvxAdjust::Left )
-                    aAttr.Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) 
);
-            }
+            auto eFrameDirection = bLeftToRight ? 
SvxFrameDirection::Horizontal_LR_TB
+                                                : 
SvxFrameDirection::Horizontal_RL_TB;
+            aAttr.Put(SvxFrameDirectionItem{ eFrameDirection, 
EE_PARA_WRITINGDIR });
 
             // tdf#162120: The paragraph direction has been manually set by 
the user.
             // Don't automatically adjust the paragraph direction anymore.
diff --git a/sw/source/uibase/shells/drwtxtex.cxx 
b/sw/source/uibase/shells/drwtxtex.cxx
index d33074258223..449384313fcb 100644
--- a/sw/source/uibase/shells/drwtxtex.cxx
+++ b/sw/source/uibase/shells/drwtxtex.cxx
@@ -622,25 +622,11 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
             }
             SfxItemSetFixed<
                     EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
-                    EE_PARA_JUST, EE_PARA_JUST,
                     EE_PARA_AUTOWRITINGDIR, EE_PARA_AUTOWRITINGDIR>  aAttr( 
*aNewAttr.GetPool() );
 
-            SvxAdjust nAdjust = SvxAdjust::Left;
-            if( const SvxAdjustItem* pAdjustItem = 
aEditAttr.GetItemIfSet(EE_PARA_JUST) )
-                nAdjust = pAdjustItem->GetAdjust();
-
-            if( bLeftToRight )
-            {
-                aAttr.Put( SvxFrameDirectionItem( 
SvxFrameDirection::Horizontal_LR_TB, EE_PARA_WRITINGDIR ) );
-                if( nAdjust == SvxAdjust::Right )
-                    aAttr.Put( SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ) 
);
-            }
-            else
-            {
-                aAttr.Put( SvxFrameDirectionItem( 
SvxFrameDirection::Horizontal_RL_TB, EE_PARA_WRITINGDIR ) );
-                if( nAdjust == SvxAdjust::Left )
-                    aAttr.Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) 
);
-            }
+            auto eFrameDirection = bLeftToRight ? 
SvxFrameDirection::Horizontal_LR_TB
+                                                : 
SvxFrameDirection::Horizontal_RL_TB;
+            aAttr.Put(SvxFrameDirectionItem{ eFrameDirection, 
EE_PARA_WRITINGDIR });
 
             // tdf#162120: The paragraph direction has been manually set by 
the user.
             // Don't automatically adjust the paragraph direction anymore.
diff --git a/sw/source/uibase/shells/txtattr.cxx 
b/sw/source/uibase/shells/txtattr.cxx
index ac6e968e6fb8..7ec682e73045 100644
--- a/sw/source/uibase/shells/txtattr.cxx
+++ b/sw/source/uibase/shells/txtattr.cxx
@@ -391,20 +391,6 @@ SET_LINESPACE:
         case SID_ATTR_PARA_LEFT_TO_RIGHT :
         case SID_ATTR_PARA_RIGHT_TO_LEFT :
         {
-            SfxItemSet 
aAdjustSet(SfxItemSet::makeFixedSfxItemSet<RES_PARATR_ADJUST, 
RES_PARATR_ADJUST>(GetPool()));
-            GetShell().GetCurAttr(aAdjustSet);
-            bool bChgAdjust = false;
-            SfxItemState eAdjustState = 
aAdjustSet.GetItemState(RES_PARATR_ADJUST, false);
-            if(eAdjustState  >= SfxItemState::DEFAULT)
-            {
-                SvxAdjust eAdjust =
-                        aAdjustSet.Get(RES_PARATR_ADJUST).GetAdjust();
-                bChgAdjust = (SvxAdjust::Left  == eAdjust  &&  
SID_ATTR_PARA_RIGHT_TO_LEFT == nSlot) ||
-                             (SvxAdjust::Right == eAdjust  &&  
SID_ATTR_PARA_LEFT_TO_RIGHT == nSlot);
-            }
-            else
-                bChgAdjust = true;
-
             SvxFrameDirection eFrameDirection =
                     (SID_ATTR_PARA_LEFT_TO_RIGHT == nSlot) ?
                         SvxFrameDirection::Horizontal_LR_TB : 
SvxFrameDirection::Horizontal_RL_TB;
@@ -413,40 +399,6 @@ SET_LINESPACE:
             // tdf#162120: The paragraph direction has been manually set by 
the user.
             // Don't automatically adjust the paragraph direction anymore.
             aSet.Put(SvxAutoFrameDirectionItem(false, 
RES_PARATR_AUTOFRAMEDIR));
-
-            if (bChgAdjust)
-            {
-                SvxAdjust eAdjust = (SID_ATTR_PARA_LEFT_TO_RIGHT == nSlot) ?
-                        SvxAdjust::Left : SvxAdjust::Right;
-                SvxAdjustItem aAdjust( eAdjust, RES_PARATR_ADJUST );
-                aSet.Put( aAdjust );
-                aAdjust.SetWhich(SID_ATTR_PARA_ADJUST);
-                GetView().GetViewFrame().GetBindings().SetState( aAdjust );
-                // Toggle numbering alignment
-                const SwNumRule* pCurRule = 
GetShell().GetNumRuleAtCurrCursorPos();
-                if( pCurRule )
-                {
-                    SvxNumRule aRule = pCurRule->MakeSvxNumRule();
-
-                    for(sal_uInt16 i = 0; i < aRule.GetLevelCount(); i++)
-                    {
-                        SvxNumberFormat aFormat(aRule.GetLevel(i));
-                        if(SvxAdjust::Left == aFormat.GetNumAdjust())
-                            aFormat.SetNumAdjust( SvxAdjust::Right );
-
-                        else if(SvxAdjust::Right == aFormat.GetNumAdjust())
-                            aFormat.SetNumAdjust( SvxAdjust::Left );
-
-                        aRule.SetLevel(i, aFormat, aRule.Get(i) != nullptr);
-                    }
-                    SwNumRule aSetRule( pCurRule->GetName(),
-                                        pCurRule->Get( 0 
).GetPositionAndSpaceMode() );
-                    aSetRule.SetSvxRule( aRule, GetShell().GetDoc());
-                    aSetRule.SetAutoRule( true );
-                    // no start or continuation of a list - list style is only 
changed
-                    GetShell().SetCurNumRule( aSetRule, false );
-                }
-            }
         }
         break;
         case SID_ATTR_PARA_HYPHENZONE:

Reply via email to