[Libreoffice-commits] core.git: Branch 'libreoffice-7-2' - sw/source

Justin Luth (via logerrit) logerrit at kemper.freedesktop.org
Mon Aug 9 17:30:35 UTC 2021


 sw/source/core/txtnode/txtedt.cxx |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

New commits:
commit ae63df06b49c0439f8a7532656dbf6063dccdc4f
Author:     Justin Luth <justin_luth at sil.org>
AuthorDate: Thu Jul 15 09:07:23 2021 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Mon Aug 9 19:30:01 2021 +0200

    tdf#65535 sw spell: ignore comment marker when checking spelling
    
    A comment in the middle of the word should not render it as
    a misspelling. So strip it out when checking - like hidden or redlines.
    
    One existing problem is that if the word is STILL misspelled,
    then replacing it will remove the in-word comment.
    That was true before this patch, so it is just another
    deirable enhancement to try to avoid that.
    
    Change-Id: Ic69385d5bbeca2d17b1969211c118d4d38e6a22f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118972
    Tested-by: Jenkins
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: Justin Luth <justin_luth at sil.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>
    (cherry picked from commit a6555eb809e2580562cd431085e35a23b7d47f9a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119856

diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index 8913fbd94810..7caa528b0dde 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -124,6 +124,19 @@ struct SwParaIdleData_Impl
         bAutoComplDirty     ( true ) {};
 };
 
+static bool lcl_HasComments(const SwTextNode& rNode)
+{
+    sal_Int32 nPosition = rNode.GetText().indexOf(CH_TXTATR_INWORD);
+    while (nPosition != -1)
+    {
+        const SwTextAttr* pAttr = rNode.GetTextAttrForCharAt(nPosition);
+        if (pAttr && pAttr->Which() == RES_TXTATR_ANNOTATION)
+            return true;
+        nPosition = rNode.GetText().indexOf(CH_TXTATR_INWORD, nPosition + 1);
+    }
+    return false;
+}
+
 /*
  * This has basically the same function as SwScriptInfo::MaskHiddenRanges,
  * only for deleted redlines
@@ -939,6 +952,7 @@ bool SwTextNode::Spell(SwSpellArgs* pArgs)
     // modify string according to redline information and hidden text
     const OUString aOldText( m_Text );
     OUStringBuffer buf(m_Text);
+    const bool bContainsComments = lcl_HasComments(*this);
     const bool bRestoreString =
         lcl_MaskRedlinesAndHiddenText(*this, buf, 0, m_Text.getLength());
     if (bRestoreString)
@@ -1024,7 +1038,7 @@ bool SwTextNode::Spell(SwSpellArgs* pArgs)
                         // redlines can leave "in word" character within word,
                         // we must remove them before spell checking
                         // to avoid false alarm
-                        ( bRestoreString && pArgs->xSpeller->isValid( rWord.replaceAll(OUStringChar(CH_TXTATR_INWORD), ""),
+                        ( (bRestoreString || bContainsComments) && pArgs->xSpeller->isValid( rWord.replaceAll(OUStringChar(CH_TXTATR_INWORD), ""),
                             static_cast<sal_uInt16>(eActLang), Sequence< PropertyValue >() ) ) )
                     {
                         pArgs->xSpellAlt = nullptr;
@@ -1243,6 +1257,7 @@ SwRect SwTextFrame::AutoSpell_(SwTextNode & rNode, sal_Int32 nActPos)
     // modify string according to redline information and hidden text
     const OUString aOldText( pNode->GetText() );
     OUStringBuffer buf(pNode->m_Text);
+    const bool bContainsComments = lcl_HasComments(rNode);
     const bool bRestoreString =
         lcl_MaskRedlinesAndHiddenText(*pNode, buf, 0, pNode->GetText().getLength());
     if (bRestoreString)
@@ -1326,7 +1341,7 @@ SwRect SwTextFrame::AutoSpell_(SwTextNode & rNode, sal_Int32 nActPos)
                     // redlines can leave "in word" character within word,
                     // we must remove them before spell checking
                     // to avoid false alarm
-                    (!bRestoreString || !xSpell->isValid( rWord.replaceAll(OUStringChar(CH_TXTATR_INWORD), ""),
+                    ((!bRestoreString && !bContainsComments) || !xSpell->isValid( rWord.replaceAll(OUStringChar(CH_TXTATR_INWORD), ""),
                             static_cast<sal_uInt16>(eActLang), Sequence< PropertyValue >() ) ) )
                 {
                     sal_Int32 nSmartTagStt = nBegin;


More information about the Libreoffice-commits mailing list