summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2021-07-15 09:07:23 +0200
committerLászló Németh <nemeth@numbertext.org>2021-08-09 19:30:01 +0200
commitae63df06b49c0439f8a7532656dbf6063dccdc4f (patch)
treed9bfac2383486fe57ac7c05984e71bc6275f0f4e /sw
parent214a649d7d4a2bab8c4d8829bacb16e72c24e026 (diff)
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@numbertext.org> Reviewed-by: Justin Luth <justin_luth@sil.org> Reviewed-by: László Németh <nemeth@numbertext.org> (cherry picked from commit a6555eb809e2580562cd431085e35a23b7d47f9a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119856
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/txtnode/txtedt.cxx19
1 files changed, 17 insertions, 2 deletions
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;