Blame SOURCES/0001-Resolves-tdf-132288-don-t-merge-adjacent-properties-.patch

a977ad
From fd1692b657838f137c8974eae7730510b7d190df Mon Sep 17 00:00:00 2001
a977ad
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
a977ad
Date: Fri, 24 Apr 2020 16:38:26 +0100
a977ad
Subject: [PATCH] Resolves: tdf#132288 don't merge adjacent properties for
a977ad
 spell checking
a977ad
MIME-Version: 1.0
a977ad
Content-Type: text/plain; charset=UTF-8
a977ad
Content-Transfer-Encoding: 8bit
a977ad
a977ad
spell checking relies on each attribute chunk being unmerged with identical
a977ad
adjacent chunks
a977ad
a977ad
squash includes...
a977ad
a977ad
nStartPosition and nEndPosition are always the same
a977ad
a977ad
and
a977ad
a977ad
tdf#132288 preservation of footnote depends on reverse iteration
a977ad
a977ad
like TextCharAttribList::FindAttrib does which spell checking
a977ad
used before
a977ad
a977ad
commit 243b5b392906042ab03800e0b5765e6f3513372c
a977ad
Author: Caolán McNamara <caolanm@redhat.com>
a977ad
Date:   Fri Jun 14 21:56:44 2019 +0100
a977ad
a977ad
    weld SpellDialog
a977ad
a977ad
converted to use an EditEngine instead of a TextEngine in order to
a977ad
be able to host it in a native widget
a977ad
a977ad
Change-Id: Ia835fa054cad0dee4304f16724b9eb0c29b46102
a977ad
---
a977ad
 cui/source/dialogs/SpellDialog.cxx | 37 ++++++++++++++++--------------
a977ad
 editeng/inc/editdoc.hxx            |  3 +++
a977ad
 editeng/source/editeng/editdoc.cxx | 12 +++++++++-
a977ad
 editeng/source/editeng/editeng.cxx |  4 ++++
a977ad
 include/editeng/editeng.hxx        |  5 ++++
a977ad
 5 files changed, 43 insertions(+), 18 deletions(-)
a977ad
a977ad
diff --git a/cui/source/dialogs/SpellDialog.cxx b/cui/source/dialogs/SpellDialog.cxx
a977ad
index 1bb15c934552..17bff36056fb 100644
a977ad
--- a/cui/source/dialogs/SpellDialog.cxx
a977ad
+++ b/cui/source/dialogs/SpellDialog.cxx
a977ad
@@ -1142,6 +1142,8 @@ void SentenceEditWindow_Impl::SetDrawingArea(weld::DrawingArea* pDrawingArea)
a977ad
                pDrawingArea->get_text_height() * 6);
a977ad
     pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
a977ad
     WeldEditView::SetDrawingArea(pDrawingArea);
a977ad
+    // tdf#132288 don't merge equal adjacent attributes
a977ad
+    m_xEditEngine->DisableAttributeExpanding();
a977ad
 }
a977ad
 
a977ad
 SentenceEditWindow_Impl::~SentenceEditWindow_Impl()
a977ad
@@ -1150,13 +1152,14 @@ SentenceEditWindow_Impl::~SentenceEditWindow_Impl()
a977ad
 
a977ad
 namespace
a977ad
 {
a977ad
-    const EECharAttrib* FindCharAttrib(int nStartPosition, int nEndPosition, sal_uInt16 nWhich, std::vector<EECharAttrib>& rAttribList)
a977ad
+    const EECharAttrib* FindCharAttrib(int nPosition, sal_uInt16 nWhich, std::vector<EECharAttrib>& rAttribList)
a977ad
     {
a977ad
-        for (const auto& rTextAtr : rAttribList)
a977ad
+        for (auto it = rAttribList.rbegin(); it != rAttribList.rend(); ++it)
a977ad
         {
a977ad
+            const auto& rTextAtr = *it;
a977ad
             if (rTextAtr.pAttr->Which() != nWhich)
a977ad
                 continue;
a977ad
-            if (rTextAtr.nStart <= nStartPosition && rTextAtr.nEnd >= nEndPosition)
a977ad
+            if (rTextAtr.nStart <= nPosition && rTextAtr.nEnd >= nPosition)
a977ad
             {
a977ad
                 return &rTextAtr;
a977ad
             }
a977ad
@@ -1272,8 +1275,8 @@ bool SentenceEditWindow_Impl::KeyInput(const KeyEvent& rKeyEvt)
a977ad
         m_xEditEngine->GetCharAttribs(0, aAttribList);
a977ad
 
a977ad
         auto nCursor = aCurrentSelection.nStartPos;
a977ad
-        const EECharAttrib* pBackAttr = FindCharAttrib(nCursor, nCursor, EE_CHAR_BKGCOLOR, aAttribList);
a977ad
-        const EECharAttrib* pErrorAttr = FindCharAttrib(nCursor, nCursor, EE_CHAR_GRABBAG, aAttribList);
a977ad
+        const EECharAttrib* pBackAttr = FindCharAttrib(nCursor, EE_CHAR_BKGCOLOR, aAttribList);
a977ad
+        const EECharAttrib* pErrorAttr = FindCharAttrib(nCursor, EE_CHAR_GRABBAG, aAttribList);
a977ad
         const EECharAttrib* pBackAttrLeft = nullptr;
a977ad
         const EECharAttrib* pErrorAttrLeft = nullptr;
a977ad
 
a977ad
@@ -1299,8 +1302,8 @@ bool SentenceEditWindow_Impl::KeyInput(const KeyEvent& rKeyEvt)
a977ad
                 while (nCursor < aCurrentSelection.nEndPos)
a977ad
                 {
a977ad
                     ++nCursor;
a977ad
-                    const EECharAttrib* pIntBackAttr = FindCharAttrib(nCursor, nCursor, EE_CHAR_BKGCOLOR, aAttribList);
a977ad
-                    const EECharAttrib* pIntErrorAttr = FindCharAttrib(nCursor, nCursor, EE_CHAR_GRABBAG, aAttribList);
a977ad
+                    const EECharAttrib* pIntBackAttr = FindCharAttrib(nCursor, EE_CHAR_BKGCOLOR, aAttribList);
a977ad
+                    const EECharAttrib* pIntErrorAttr = FindCharAttrib(nCursor, EE_CHAR_GRABBAG, aAttribList);
a977ad
                     //if any attr has been found then BRACE
a977ad
                     if (pIntBackAttr || pIntErrorAttr)
a977ad
                         nSelectionType = BRACE;
a977ad
@@ -1342,8 +1345,8 @@ bool SentenceEditWindow_Impl::KeyInput(const KeyEvent& rKeyEvt)
a977ad
             if (nCursor)
a977ad
             {
a977ad
                 --nCursor;
a977ad
-                pBackAttrLeft = FindCharAttrib(nCursor, nCursor, EE_CHAR_BKGCOLOR, aAttribList);
a977ad
-                pErrorAttrLeft = FindCharAttrib(nCursor, nCursor, EE_CHAR_GRABBAG, aAttribList);
a977ad
+                pBackAttrLeft = FindCharAttrib(nCursor, EE_CHAR_BKGCOLOR, aAttribList);
a977ad
+                pErrorAttrLeft = FindCharAttrib(nCursor, EE_CHAR_GRABBAG, aAttribList);
a977ad
                 bHasFieldLeft = pBackAttrLeft !=nullptr;
a977ad
                 bHasErrorLeft = pErrorAttrLeft != nullptr;
a977ad
                 ++nCursor;
a977ad
@@ -1492,8 +1495,8 @@ bool SentenceEditWindow_Impl::KeyInput(const KeyEvent& rKeyEvt)
a977ad
         //start position
a977ad
         if (!IsUndoEditMode() && bIsErrorActive)
a977ad
         {
a977ad
-            const EECharAttrib* pFontColor = FindCharAttrib(nCursor, nCursor, EE_CHAR_COLOR, aAttribList);
a977ad
-            const EECharAttrib* pErrorAttrib = FindCharAttrib(m_nErrorStart, m_nErrorStart, EE_CHAR_GRABBAG, aAttribList);
a977ad
+            const EECharAttrib* pFontColor = FindCharAttrib(nCursor, EE_CHAR_COLOR, aAttribList);
a977ad
+            const EECharAttrib* pErrorAttrib = FindCharAttrib(m_nErrorStart, EE_CHAR_GRABBAG, aAttribList);
a977ad
             if (pFontColor && pErrorAttrib)
a977ad
             {
a977ad
                 m_nErrorStart = pFontColor->nStart;
a977ad
@@ -1695,7 +1698,7 @@ int SentenceEditWindow_Impl::ChangeMarkedWord(const OUString& rNewWord, Language
a977ad
     auto nDiffLen = rNewWord.getLength() - m_nErrorEnd + m_nErrorStart;
a977ad
     //Remove spell error attribute
a977ad
     m_xEditEngine->UndoActionStart(SPELLUNDO_MOVE_ERROREND);
a977ad
-    const EECharAttrib* pErrorAttrib = FindCharAttrib(m_nErrorStart, m_nErrorStart, EE_CHAR_GRABBAG, aAttribList);
a977ad
+    const EECharAttrib* pErrorAttrib = FindCharAttrib(m_nErrorStart, EE_CHAR_GRABBAG, aAttribList);
a977ad
     DBG_ASSERT(pErrorAttrib, "no error attribute found");
a977ad
     bool bSpellErrorDescription = false;
a977ad
     SpellErrorDescription aSpellErrorDescription;
a977ad
@@ -1706,7 +1709,7 @@ int SentenceEditWindow_Impl::ChangeMarkedWord(const OUString& rNewWord, Language
a977ad
         bSpellErrorDescription = true;
a977ad
     }
a977ad
 
a977ad
-    const EECharAttrib* pBackAttrib = FindCharAttrib(m_nErrorStart, m_nErrorStart, EE_CHAR_BKGCOLOR, aAttribList);
a977ad
+    const EECharAttrib* pBackAttrib = FindCharAttrib(m_nErrorStart, EE_CHAR_BKGCOLOR, aAttribList);
a977ad
 
a977ad
     ESelection aSel(0, m_nErrorStart, 0, m_nErrorEnd);
a977ad
     m_xEditEngine->QuickInsertText(rNewWord, aSel);
a977ad
@@ -1721,7 +1724,7 @@ int SentenceEditWindow_Impl::ChangeMarkedWord(const OUString& rNewWord, Language
a977ad
         //attributes following an error at the start of the text are not moved but expanded from the
a977ad
         //text engine - this is done to keep full-paragraph-attributes
a977ad
         //in the current case that handling is not desired
a977ad
-        const EECharAttrib* pLangAttrib = FindCharAttrib(m_nErrorEnd, m_nErrorEnd, EE_CHAR_LANGUAGE, aAttribList);
a977ad
+        const EECharAttrib* pLangAttrib = FindCharAttrib(m_nErrorEnd, EE_CHAR_LANGUAGE, aAttribList);
a977ad
 
a977ad
         if (pLangAttrib && !pLangAttrib->nStart && pLangAttrib->nEnd == nTextLen)
a977ad
         {
a977ad
@@ -1776,7 +1779,7 @@ bool SentenceEditWindow_Impl::GetErrorDescription(SpellErrorDescription& rSpellE
a977ad
     std::vector<EECharAttrib> aAttribList;
a977ad
     m_xEditEngine->GetCharAttribs(0, aAttribList);
a977ad
 
a977ad
-    if (const EECharAttrib* pEECharAttrib = FindCharAttrib(nPosition, nPosition, EE_CHAR_GRABBAG, aAttribList))
a977ad
+    if (const EECharAttrib* pEECharAttrib = FindCharAttrib(nPosition, EE_CHAR_GRABBAG, aAttribList))
a977ad
     {
a977ad
         ExtractErrorDescription(*pEECharAttrib, rSpellErrorDescription);
a977ad
         return true;
a977ad
@@ -1895,7 +1898,7 @@ svx::SpellPortions SentenceEditWindow_Impl::CreateSpellPortions() const
a977ad
         const EECharAttrib* pError = nullptr;
a977ad
         while (nCursor < nTextLen)
a977ad
         {
a977ad
-            const EECharAttrib* pLang = FindCharAttrib(nCursor, nCursor, EE_CHAR_LANGUAGE, aAttribList);
a977ad
+            const EECharAttrib* pLang = FindCharAttrib(nCursor, EE_CHAR_LANGUAGE, aAttribList);
a977ad
             if(pLang && pLang != pLastLang)
a977ad
             {
a977ad
                 eLang = static_cast<const SvxLanguageItem*>(pLang->pAttr)->GetLanguage();
a977ad
@@ -1903,7 +1906,7 @@ svx::SpellPortions SentenceEditWindow_Impl::CreateSpellPortions() const
a977ad
                 lcl_InsertBreakPosition_Impl(aBreakPositions, pLang->nEnd, eLang);
a977ad
                 pLastLang = pLang;
a977ad
             }
a977ad
-            pError = FindCharAttrib(nCursor, nCursor, EE_CHAR_GRABBAG, aAttribList);
a977ad
+            pError = FindCharAttrib(nCursor, EE_CHAR_GRABBAG, aAttribList);
a977ad
             if (pError && pLastError != pError)
a977ad
             {
a977ad
                 lcl_InsertBreakPosition_Impl(aBreakPositions, pError->nStart, eLang);
a977ad
diff --git a/editeng/inc/editdoc.hxx b/editeng/inc/editdoc.hxx
a977ad
index 089addc59c07..258fa945912c 100644
a977ad
--- a/editeng/inc/editdoc.hxx
a977ad
+++ b/editeng/inc/editdoc.hxx
a977ad
@@ -747,6 +747,7 @@ private:
a977ad
 
a977ad
     bool            bOwnerOfPool:1;
a977ad
     bool            bModified:1;
a977ad
+    bool            bDisableAttributeExpanding:1;
a977ad
 
a977ad
 private:
a977ad
     void            ImplDestroyContents();
a977ad
@@ -761,6 +762,8 @@ public:
a977ad
     bool            IsModified() const      { return bModified; }
a977ad
     void            SetModified( bool b );
a977ad
 
a977ad
+    void            DisableAttributeExpanding() { bDisableAttributeExpanding = true; }
a977ad
+
a977ad
     void            SetModifyHdl( const Link<LinkParamNone*,void>& rLink ) { aModifyHdl = rLink; }
a977ad
 
a977ad
     void            CreateDefFont( bool bUseStyles );
a977ad
diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx
a977ad
index 73a356054741..aacc0b2c7b6b 100644
a977ad
--- a/editeng/source/editeng/editdoc.cxx
a977ad
+++ b/editeng/source/editeng/editdoc.cxx
a977ad
@@ -1906,7 +1906,8 @@ EditDoc::EditDoc( SfxItemPool* pPool ) :
a977ad
     bIsTopToBottomVert(false),
a977ad
     bIsFixedCellHeight(false),
a977ad
     bOwnerOfPool(pPool == nullptr),
a977ad
-    bModified(false)
a977ad
+    bModified(false),
a977ad
+    bDisableAttributeExpanding(false)
a977ad
 {
a977ad
     // Don't create an empty node, Clear() will be called in EditEngine-CTOR
a977ad
 };
a977ad
@@ -2354,6 +2355,15 @@ void EditDoc::InsertAttribInSelection( ContentNode* pNode, sal_Int32 nStart, sal
a977ad
 
a977ad
     RemoveAttribs( pNode, nStart, nEnd, pStartingAttrib, pEndingAttrib, rPoolItem.Which() );
a977ad
 
a977ad
+    // tdf#132288  By default inserting an attribute beside another that is of
a977ad
+    // the same type expands the original instead of inserting another. But the
a977ad
+    // spell check dialog doesn't want that behaviour
a977ad
+    if (bDisableAttributeExpanding)
a977ad
+    {
a977ad
+        pStartingAttrib = nullptr;
a977ad
+        pEndingAttrib = nullptr;
a977ad
+    }
a977ad
+
a977ad
     if ( pStartingAttrib && pEndingAttrib &&
a977ad
          ( *(pStartingAttrib->GetItem()) == rPoolItem ) &&
a977ad
          ( *(pEndingAttrib->GetItem()) == rPoolItem ) )
a977ad
diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx
a977ad
index 458f71b34d3f..f46106a5773c 100644
a977ad
--- a/editeng/source/editeng/editeng.cxx
a977ad
+++ b/editeng/source/editeng/editeng.cxx
a977ad
@@ -2802,6 +2802,10 @@ bool EditEngine::IsPageOverflow() {
a977ad
     return pImpEditEngine->IsPageOverflow();
a977ad
 }
a977ad
 
a977ad
+void EditEngine::DisableAttributeExpanding() {
a977ad
+    pImpEditEngine->GetEditDoc().DisableAttributeExpanding();
a977ad
+}
a977ad
+
a977ad
 EFieldInfo::EFieldInfo()
a977ad
 {
a977ad
 }
a977ad
diff --git a/include/editeng/editeng.hxx b/include/editeng/editeng.hxx
a977ad
index f585ce8b5796..7d4129c0ad0b 100644
a977ad
--- a/include/editeng/editeng.hxx
a977ad
+++ b/include/editeng/editeng.hxx
a977ad
@@ -618,6 +618,11 @@ public:
a977ad
     sal_Int32 GetOverflowingLineNum() const;
a977ad
     void ClearOverflowingParaNum();
a977ad
     bool IsPageOverflow();
a977ad
+
a977ad
+    // tdf#132288  By default inserting an attribute beside another that is of
a977ad
+    // the same type expands the original instead of inserting another. But the
a977ad
+    // spell check dialog doesn't want that behaviour
a977ad
+    void DisableAttributeExpanding();
a977ad
 };
a977ad
 
a977ad
 #endif // INCLUDED_EDITENG_EDITENG_HXX
a977ad
-- 
a977ad
2.25.3
a977ad