summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2020-12-01 15:12:54 +0100
committerLászló Németh <nemeth@numbertext.org>2020-12-02 18:06:08 +0100
commitd08e41379d39a3b552c2c8a34fe1c4849bb80bc9 (patch)
tree08cedf829322f93544da821f366c99a051d1534d
parent0956226ca535a62ab22d8d2502b159037c327f7d (diff)
tdf#66043 sw: fix spell checking of word with deletion
Correct words were underlined as spelling mistakes, if they contained tracked deletions, related to the unwanted CH_TXTATR_INWORD characters (result of removing tracked deletions) at calling spell checking API functions. Fix it by checking the "invalid" words without CH_TXTATR_INWORD characters, too. Change-Id: I6d8a8d619a571dfb613991cb8cf67faab57de4c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106988 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r--sw/qa/uitest/data/tdf66043.fodt35
-rw-r--r--sw/qa/uitest/writer_tests4/spellDialog.py33
-rw-r--r--sw/source/core/txtnode/txtedt.cxx15
3 files changed, 79 insertions, 4 deletions
diff --git a/sw/qa/uitest/data/tdf66043.fodt b/sw/qa/uitest/data/tdf66043.fodt
new file mode 100644
index 000000000000..5fcdde71d4ae
--- /dev/null
+++ b/sw/qa/uitest/data/tdf66043.fodt
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:officeooo="http://openoffice.org/2009/office" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <office:styles>
+ <style:style style:name="Standard" style:family="paragraph" style:class="text"/>
+ <style:default-style style:family="paragraph">
+ <style:text-properties fo:language="en" fo:country="US"/>
+ </style:default-style>
+ </office:styles>
+ <office:body>
+ <office:text>
+ <text:tracked-changes>
+ <text:changed-region xml:id="ct94277392414656" text:id="ct94277392414656">
+ <text:deletion>
+ <office:change-info>
+ <dc:creator>Unknown Author</dc:creator>
+ <dc:date>2020-12-01T12:49:53</dc:date>
+ </office:change-info>
+ <text:p text:style-name="P1">o</text:p>
+ </text:deletion>
+ </text:changed-region>
+ <text:changed-region xml:id="ct94277392490096" text:id="ct94277392490096">
+ <text:deletion>
+ <office:change-info>
+ <dc:creator>Unknown Author</dc:creator>
+ <dc:date>2020-12-01T12:50:00</dc:date>
+ </office:change-info>
+ <text:p text:style-name="P1">a</text:p>
+ </text:deletion>
+ </text:changed-region>
+ </text:tracked-changes>
+ <text:p text:style-name="P1">goo<text:change text:change-id="ct94277392414656"/>d baa<text:change text:change-id="ct94277392490096"/>d eeend</text:p>
+ </office:text>
+ </office:body>
+</office:document>
+
diff --git a/sw/qa/uitest/writer_tests4/spellDialog.py b/sw/qa/uitest/writer_tests4/spellDialog.py
index e678afea53e9..3b9e4c31f3da 100644
--- a/sw/qa/uitest/writer_tests4/spellDialog.py
+++ b/sw/qa/uitest/writer_tests4/spellDialog.py
@@ -5,6 +5,8 @@
#
import re
+import org.libreoffice.unotest
+import pathlib
from uitest.framework import UITestCase
from uitest.uihelper.common import get_state_as_dict
@@ -12,6 +14,9 @@ from uitest.uihelper.common import get_state_as_dict
from libreoffice.linguistic.linguservice import get_spellchecker
from com.sun.star.lang import Locale
+def get_url_for_data_file(file_name):
+ return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
+
class SpellingAndGrammarDialog(UITestCase):
def is_supported_locale(self, language, country):
@@ -99,4 +104,30 @@ frog, dogg, catt"""
output_text = document.Text.getString().replace('\r\n', '\n')
self.assertTrue(re.match(self.TDF46852_REGEX, output_text))
-
+
+ def test_tdf66043(self):
+ writer_doc = self.ui_test.load_file(get_url_for_data_file("tdf66043.fodt"))
+ document = self.ui_test.get_component()
+ # Step 1: Initiate spellchecking, and make sure "Check grammar" is
+ # unchecked
+ spell_dialog = self.launch_dialog()
+ checkgrammar = spell_dialog.getChild('checkgrammar')
+ if get_state_as_dict(checkgrammar)['Selected'] == 'true':
+ checkgrammar.executeAction('CLICK', ())
+ self.assertTrue(get_state_as_dict(checkgrammar)['Selected'] == 'false')
+
+ # Step 2: Click on "Correct all" for each misspelling
+ # prompt until end of document is reached.
+ changeall = spell_dialog.getChild('changeall')
+ changeall.executeAction("CLICK", ())
+
+ xCloseBtn = spell_dialog.getChild("close")
+ xCloseBtn.executeAction("CLICK", tuple())
+
+ output_text = document.Text.getString().replace('\r\n', '\n')
+ # This was "gooodgood baaad eeend" ("goood" is a deletion,
+ # "good" is an insertion by fixing the first misspelling),
+ # but now "goood" is not a misspelling because it is accepted
+ # correctly without the redline containing a deleted "o"
+ self.assertTrue(output_text == 'goood baaadbaaed eeend')
+
diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index 67aae7f85650..edc0ac296d00 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -1023,7 +1023,12 @@ bool SwTextNode::Spell(SwSpellArgs* pArgs)
}
if( pArgs->xSpellAlt.is() )
{
- if (IsSymbolAt(aScanner.GetBegin()))
+ if ( IsSymbolAt(aScanner.GetBegin()) ||
+ // 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), ""),
+ static_cast<sal_uInt16>(eActLang), Sequence< PropertyValue >() ) ) )
{
pArgs->xSpellAlt = nullptr;
}
@@ -1325,8 +1330,12 @@ SwRect SwTextFrame::AutoSpell_(SwTextNode & rNode, sal_Int32 nActPos)
{
// check for: bAlter => xHyphWord.is()
OSL_ENSURE(!bSpell || xSpell.is(), "NULL pointer");
-
- if( !xSpell->isValid( rWord, static_cast<sal_uInt16>(eActLang), Sequence< PropertyValue >() ) )
+ if( !xSpell->isValid( rWord, static_cast<sal_uInt16>(eActLang), Sequence< PropertyValue >() ) &&
+ // 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), ""),
+ static_cast<sal_uInt16>(eActLang), Sequence< PropertyValue >() ) ) )
{
sal_Int32 nSmartTagStt = nBegin;
sal_Int32 nDummy = 1;