sw/qa/uitest/data/tdf65535.fodt           |   14 ++++++++++
 sw/qa/uitest/writer_tests4/spellDialog.py |   41 ++++++++++++++++++++++++++++++
 sw/source/core/edit/edlingu.cxx           |   16 +++++++++++
 3 files changed, 71 insertions(+)

New commits:
commit 5ecb61c81238b5bc802dd5afcab18e8331ed3d9d
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Mon Dec 19 10:12:45 2022 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Mon Dec 19 11:12:42 2022 +0000

    tdf#65535 sw: fix lost comments using spelling dialog
    
    Choosing one of the spelling suggestions in the spelling
    dialog, or rewriting the bad word removed also its
    inword comment. Keep the comment at the end of the fixed word.
    
    Regression from commit b0f170d7df9cff12535d2ecfd146b32b745a8ef8
    "0xFFF9 is a better choice for CH_TXTATR_INWORD than 0x0002".
    
    Change-Id: Iaf083453fad4e0ca99e254f53b20ead86b3ba15e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144458
    Tested-by: Jenkins
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/uitest/data/tdf65535.fodt b/sw/qa/uitest/data/tdf65535.fodt
new file mode 100644
index 000000000000..b3a738bc8ac8
--- /dev/null
+++ b/sw/qa/uitest/data/tdf65535.fodt
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:meta="u
 rn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext: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:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:field="urn:openoffice:names:experimental:ooo-ms
 -interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ 
<office:meta><meta:creation-date>2022-12-17T23:29:19.781993530</meta:creation-date><dc:date>2022-12-17T23:30:52.855431377</dc:date><meta:editing-duration>PT1M34S</meta:editing-duration><meta:editing-cycles>1</meta:editing-cycles><meta:document-statistic
 meta:table-count="0" meta:image-count="0" meta:object-count="0" 
meta:page-count="1" meta:paragraph-count="1" meta:word-count="1" 
meta:character-count="4" 
meta:non-whitespace-character-count="4"/><meta:generator>LibreOfficeDev/7.5.0.0.alpha0$Linux_X86_64
 
LibreOffice_project/be538308dd5dee33436ae0e247c315df63a8b958</meta:generator></office:meta>
+ <office:body>
+  <office:text>
+   <text:p text:style-name="P1">Ba<office:annotation loext:resolved="false">
+     <dc:creator>x</dc:creator>
+     <dc:date>2022-12-17T23:29:53.289798307</dc:date>
+     <text:p text:style-name="P2"><text:span text:style-name="T1">with 
comment</text:span></text:p>
+    </office:annotation>ad</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 183a85843ab9..d7990cdf494e 100644
--- a/sw/qa/uitest/writer_tests4/spellDialog.py
+++ b/sw/qa/uitest/writer_tests4/spellDialog.py
@@ -205,4 +205,45 @@ frog, dogg, catt"""
             # This was "Baaed HTTP://www. baaad .org baaed" (skipped non-URL 
words of hypertext)
             self.assertEqual("Baaed http://www. baaed .org baaad", output_text)
 
+    def test_tdf65535(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.load_file(get_url_for_data_file("tdf65535.fodt")) 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")
+
+            # type a bad word after the word with comment
+            cursor.goRight(5, False)
+            type_text(xEdit, " baad")
+            cursor.goLeft(10, False)
+
+            # fix the first word using the spelling dialog
+            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", ())
+
+            output_text = document.Text.getString()
+            self.assertEqual("Bad baad", output_text)
+
+            # check the original comment
+            has_comment = False
+            textfields = document.getTextFields()
+            for textfield in textfields:
+                if 
textfield.supportsService("com.sun.star.text.TextField.Annotation"):
+                    has_comment = True
+
+            # This was False (lost comment)
+            self.assertEqual(True, has_comment)
+
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx
index 294d6ffede72..ab89fc5b7241 100644
--- a/sw/source/core/edit/edlingu.cxx
+++ b/sw/source/core/edit/edlingu.cxx
@@ -1164,6 +1164,22 @@ void SwEditShell::ApplyChangedSentence(const 
svx::SpellPortions& rNewPortions, b
                 // ... and apply language if necessary
                 if(aCurrentNewPortion->eLanguage != 
aCurrentOldPortion->eLanguage)
                     SetAttrItem( 
SvxLanguageItem(aCurrentNewPortion->eLanguage, nLangWhichId) );
+
+                // if there is a comment inside the original word, don't 
delete it:
+                // but keep it at the end of the replacement
+                // TODO: keep all the comments with a recursive function
+                sal_Int32 
nCommentPos(pCursor->GetText().indexOf(OUStringChar(CH_TXTATR_INWORD)));
+                if ( nCommentPos > -1 )
+                {
+                    // delete the original word after the comment
+                    pCursor->GetPoint()->AdjustContent(nCommentPos + 1);
+
+                    
mxDoc->getIDocumentContentOperations().ReplaceRange(*pCursor, OUString(), 
false);
+                    // and select only the remaining part before the comment
+                    pCursor->GetPoint()->AdjustContent(-(nCommentPos + 1));
+                    pCursor->GetMark()->AdjustContent(-1);
+                }
+
                 mxDoc->getIDocumentContentOperations().ReplaceRange(*pCursor, 
aCurrentNewPortion->sText, false);
             }
             else if(aCurrentNewPortion->eLanguage != 
aCurrentOldPortion->eLanguage)

Reply via email to