[Libreoffice-commits] core.git: sw/source

Jim Raykowski (via logerrit) logerrit at kemper.freedesktop.org
Fri May 24 10:53:16 UTC 2019


 sw/source/uibase/utlui/content.cxx |  100 +++++++++++++++++++++++++++----------
 1 file changed, 75 insertions(+), 25 deletions(-)

New commits:
commit 23fc425ff9b16371a6f83e054d63ef9d253b6236
Author:     Jim Raykowski <raykowj at gmail.com>
AuthorDate: Tue Apr 23 18:28:13 2019 -0800
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Fri May 24 12:52:01 2019 +0200

    tdf#124895 Fix multi selected chapter promote demote
    
    This patch makes multi selected chapter promote demote results the same
    as when each selection is promoted or demoted individualy. Multi
    selected chapter promotions (moved up) are done in tree list order from
    top to bottom. Multi select chapter demotions (moved down) are done in
    tree list order from bottom to top.
    
    Change-Id: Iee238fd2bc84521a6eacf6688b94fa0be1e32f67
    Reviewed-on: https://gerrit.libreoffice.org/71270
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>

diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index 2425ed1b079c..2f482dbcf94b 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -2423,6 +2423,7 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
         std::reverse(selected.begin(), selected.end());
     }
 
+    SwOutlineNodes::difference_type nDirLast = bUp ? -1 : 1;
     bool bStartedAction = false;
     for (auto const pCurrentEntry : selected)
     {
@@ -2478,8 +2479,12 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
                     nActEndPos = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
                     pEntry = Next(pEntry);
                 }
-                if (nDir == 1)
+                if (nDir == 1) // move down
                 {
+                    if (pCurrentEntry && IsSelected(pCurrentEntry->NextSibling()))
+                        nDir = nDirLast;
+                    else
+                    {
                     // If the last entry is to be moved we're done
                     if (pEntry && lcl_IsContent(pEntry))
                     {
@@ -2495,10 +2500,28 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
                             // nDest++ may only executed if pEntry != 0
                             if (pEntry)
                             {
-                                if (!lcl_IsContent(pEntry) ||
-                                    nActLevel >= static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlineLevel())
-                                {
+                                if (!lcl_IsContent(pEntry))
                                     break;
+                                else if (nActLevel >= static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlineLevel())
+                                {
+                                    // nDest needs adjusted if there are selected entries (including ancestral lineage)
+                                    // immediatly before the current moved entry.
+                                    SvTreeListEntry* pTmp = Prev(pEntry);
+                                    while (pTmp && lcl_IsContent(pTmp) &&
+                                           nActLevel < static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlineLevel())
+                                    {
+                                        while (pTmp && lcl_IsContent(pTmp) && !IsSelected(pTmp) &&
+                                               nActLevel < static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlineLevel())
+                                        {
+                                            pTmp = GetParent(pTmp);
+                                        }
+                                        if (!IsSelected(pTmp))
+                                            break;
+                                        pTmp = Prev(pTmp);
+                                        nDest = static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlinePos();
+                                    }
+                                    if (!IsSelected(pEntry->PrevSibling()))
+                                        break;
                                 }
                                 else
                                 {
@@ -2506,37 +2529,64 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
                                 }
                             }
                         }
-                        nDir = nDest - nActEndPos;
+                        nDirLast = nDir = nDest - nActEndPos;
                         // If no entry was found that allows insertion before
                         // it, we just move it to the end.
                     }
                     else
-                        nDir = 0;
+                        nDirLast = nDir = 0;
+                    }
                 }
-                else
+                else // move up
                 {
-                    SwOutlineNodes::size_type nDest = nActPos;
-                    pEntry = pCurrentEntry;
-                    while (pEntry && nDest)
+                    if (pCurrentEntry && IsSelected(pCurrentEntry->PrevSibling()))
+                        nDir = nDirLast;
+                    else
                     {
-                        pEntry = Prev(pEntry);
-                        assert(pEntry == nullptr || !lcl_IsContent(pEntry) || dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
-                        if (pEntry && lcl_IsContent(pEntry))
-                        {
-                            nDest = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
-                        }
-                        else
-                        {
-                            nDest = 0; // presumably?
-                        }
-                        if (pEntry &&
-                            (!lcl_IsContent(pEntry)
-                             || nActLevel >= static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlineLevel()))
+                        SwOutlineNodes::size_type nDest = nActPos;
+                        pEntry = pCurrentEntry;
+                        while (pEntry && nDest)
                         {
-                            break;
+                            pEntry = Prev(pEntry);
+                            assert(pEntry == nullptr || !lcl_IsContent(pEntry) || dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
+                            if (pEntry && lcl_IsContent(pEntry))
+                            {
+                                nDest = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
+                            }
+                            else
+                            {
+                                nDest = 0; // presumably?
+                            }
+                            if (pEntry)
+                            {
+                                if (!lcl_IsContent(pEntry))
+                                    break;
+                                else if (nActLevel >= static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlineLevel())
+                                {
+                                    // nDest needs adjusted if there are selected entries immediately
+                                    // after the level change.
+                                    SvTreeListEntry* pTmp = Next(pEntry);
+                                    while (pTmp && lcl_IsContent(pTmp) &&
+                                           nActLevel < static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlineLevel() &&
+                                           IsSelected(pTmp))
+                                    {
+                                        nDest = static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlinePos();
+                                        const auto nLevel = static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlineLevel();
+                                        // account for selected entries' decendent lineage
+                                        pTmp = Next(pTmp);
+                                        while (pTmp && lcl_IsContent(pTmp) &&
+                                               nLevel < static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlineLevel())
+                                        {
+                                            nDest = static_cast<SwOutlineContent*>(pTmp->GetUserData())->GetOutlinePos();
+                                            pTmp = Next(pTmp);
+                                        }
+                                    }
+                                    break;
+                                }
+                            }
                         }
+                        nDirLast = nDir = nDest - nActPos;
                     }
-                    nDir = nDest - nActPos;
                 }
                 if (nDir)
                 {


More information about the Libreoffice-commits mailing list