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

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