summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2022-12-11 19:33:13 +0100
committerLászló Németh <nemeth@numbertext.org>2022-12-13 14:41:41 +0000
commitec8fdffec29de7c80da0c2a440e467c35a297119 (patch)
tree95222302eb3361bb059942f5d46b53476c1da57f /sw
parent57e2245abf50cbd207d5c9c57ed67c055f8afcd6 (diff)
tdf#152492 sw: fix unwanted spell checking of parts of URLs
In new documents, spell checking started to report spelling mistakes within the recognized URLs. Regression from commit 2cca160f8bfc4597cf0ad3aaaf0017a5210ea0ec "tdf#126657, tdf#145104: Don’t set language to none on defined styles". Note: skipping spell checking of recognized URLs was specified by http://specs.openoffice.org/appwide/linguistic/Spellcheckdialog.sxw, see also https://bz.apache.org/ooo/show_bug.cgi?id=40133. Unfortunately, the original implementation caused possible regressions in text layout, so it was reverted in the previous commit. Change-Id: Ic5f84c8ec195677640a8870f2c484f3b6ef8b9db Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143946 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/uitest/writer_tests4/spellDialog.py33
-rw-r--r--sw/source/core/txtnode/txtedt.cxx10
2 files changed, 40 insertions, 3 deletions
diff --git a/sw/qa/uitest/writer_tests4/spellDialog.py b/sw/qa/uitest/writer_tests4/spellDialog.py
index 4d2b4b6222ee..d4b19132c90c 100644
--- a/sw/qa/uitest/writer_tests4/spellDialog.py
+++ b/sw/qa/uitest/writer_tests4/spellDialog.py
@@ -10,6 +10,7 @@
import re
from uitest.framework import UITestCase
from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
+from uitest.uihelper.common import type_text
from libreoffice.linguistic.linguservice import get_spellchecker
from com.sun.star.lang import Locale
@@ -138,4 +139,34 @@ frog, dogg, catt"""
# correctly without the redline containing a deleted "o"
self.assertEqual(output_text, 'goood baaadbaaed eeend')
-# vim: set shiftwidth=4 softtabstop=4 expandtab: \ No newline at end of file
+ def test_DoNotCheckURL(self):
+ supported_locale = self.is_supported_locale("en", "US")
+ if not supported_locale:
+ self.skipTest("no dictionary support for en_US available")
+
+ with self.ui_test.create_doc_in_start_center("writer") as document:
+ cursor = document.getCurrentController().getViewCursor()
+ # Inserted text must be en_US, so make sure to set language in current location
+ cursor.CharLocale = Locale("en", "US", "")
+
+ xMainWindow = self.xUITest.getTopFocusWindow()
+ xEdit = xMainWindow.getChild("writer_edit")
+
+ # URL is recognized during typing
+ type_text(xEdit, "baaad http://www.baaad.org baaad baaad")
+
+ with self.ui_test.execute_modeless_dialog_through_command(".uno:SpellingAndGrammarDialog", close_button="close") as xDialog:
+ checkgrammar = xDialog.getChild('checkgrammar')
+ if get_state_as_dict(checkgrammar)['Selected'] == 'true':
+ checkgrammar.executeAction('CLICK', ())
+ self.assertTrue(get_state_as_dict(checkgrammar)['Selected'] == 'false')
+
+ change = xDialog.getChild('change')
+ change.executeAction("CLICK", ())
+ change.executeAction("CLICK", ())
+
+ output_text = document.Text.getString()
+ # This was "Baaed HTTP://www.baaad.org baaad baaad" (spelling URLs)
+ self.assertEqual("Baaed http://www.baaad.org baaed baaad", output_text)
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index 60c4685470dc..b0e0b0d4b6a6 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -992,12 +992,15 @@ bool SwTextNode::Spell(SwSpellArgs* pArgs)
{
const OUString& rWord = aScanner.GetWord();
+ // skip URLs
+ bool bHyperlink = GetTextAttrAt(aScanner.GetBegin(), RES_TXTATR_INETFMT) ? true: false;
+
// get next language for next word, consider language attributes
// within the word
LanguageType eActLang = aScanner.GetCurrentLanguage();
DetectAndMarkMissingDictionaries( GetTextNode()->GetDoc(), pArgs->xSpeller, eActLang );
- if( rWord.getLength() > 0 && LANGUAGE_NONE != eActLang )
+ if( rWord.getLength() > 0 && LANGUAGE_NONE != eActLang && !bHyperlink )
{
if (pArgs->xSpeller.is())
{
@@ -1301,8 +1304,11 @@ SwRect SwTextFrame::AutoSpell_(SwTextNode & rNode, sal_Int32 nActPos)
LanguageType eActLang = aScanner.GetCurrentLanguage();
DetectAndMarkMissingDictionaries( rDoc, xSpell, eActLang );
+ // skip URLs
+ bool bHyperlink = pNode->GetTextAttrAt(nBegin, RES_TXTATR_INETFMT) ? true: false;
+
bool bSpell = xSpell.is() && xSpell->hasLanguage( static_cast<sal_uInt16>(eActLang) );
- if( bSpell && !rWord.isEmpty() )
+ if( bSpell && !rWord.isEmpty() && !bHyperlink )
{
// check for: bAlter => xHyphWord.is()
OSL_ENSURE(!bSpell || xSpell.is(), "NULL pointer");