cui/source/options/optdict.cxx |   39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)

New commits:
commit b1568a4cd8b439de19aab2bfe5f8f8465e4dc6af
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Tue May 9 21:51:10 2023 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed May 10 09:54:13 2023 +0200

    tdf#154499 spell checking: allow phrases in custom dictionary
    
    Adding phrases, i.e. space separated word sequences is allowed
    in custom dictionaries and in replacement text of the negative
    custom dictionaries.
    
    Follow-up to commit 5619fc438273cd15e78539e78b8af751bca24b1a
    "tdf#154499 sw spell checking: add 2-word phrase checking".
    
    Change-Id: Id82dafcd5ca41842e78f2121579f5b46857bfca9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151596
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/cui/source/options/optdict.cxx b/cui/source/options/optdict.cxx
index f0efb39ca18f..66b2c7f06a0c 100644
--- a/cui/source/options/optdict.cxx
+++ b/cui/source/options/optdict.cxx
@@ -67,6 +67,23 @@ static OUString getNormDicEntry_Impl(std::u16string_view 
rText)
     return aTmp.replaceAll("=", "");
 }
 
+// tdf#154499 separate words of a phrase only by a single space,
+// i.e. trim terminating spaces and replace space sequences with single spaces
+static OUString fixSpace(OUString sText)
+{
+    sText = sText.trim();
+
+    sal_Int32 nLen;
+    do
+    {
+        nLen = sText.getLength();
+        sText = sText.replaceAll("  ", " ");
+    }
+    while ( sText.getLength() < nLen );
+
+    return sText;
+}
+
 namespace {
 
 // Compare Dictionary Entry  result
@@ -281,10 +298,6 @@ 
SvxEditDictionaryDialog::SvxEditDictionaryDialog(weld::Window* pParent, std::u16
 
     m_xLangLB->SetLanguageList( SvxLanguageListFlags::ALL, true, true );
 
-    Link<OUString&,bool> aLink = LINK(this, SvxEditDictionaryDialog, 
InsertTextHdl);
-    m_xReplaceED->connect_insert_text(aLink);
-    m_xWordED->connect_insert_text(aLink);
-
     if ( nCount > 0 )
     {
         m_xAllDictsLB->set_active_text(aLookUpEntry);
@@ -598,9 +611,9 @@ bool SvxEditDictionaryDialog::NewDelHdl(const weld::Widget* 
pBtn)
     if (pBtn == m_xNewReplacePB.get() || m_xNewReplacePB->get_sensitive())
     {
         int nEntry = m_pWordsLB->get_selected_index();
-        OUString aNewWord(m_xWordED->get_text());
+        OUString aNewWord(fixSpace(m_xWordED->get_text()));
         OUString sEntry(aNewWord);
-        OUString aReplaceStr(m_xReplaceED->get_text());
+        OUString aReplaceStr(fixSpace(m_xReplaceED->get_text()));
 
         DictionaryError nAddRes = DictionaryError::UNKNOWN;
         int nPos = m_xAllDictsLB->get_active();
@@ -673,7 +686,7 @@ IMPL_LINK(SvxEditDictionaryDialog, ModifyHdl, weld::Entry&, 
rEdt, void)
     OUString rEntry = rEdt.get_text();
 
     sal_Int32 nWordLen = rEntry.getLength();
-    const OUString& rRepString = m_xReplaceED->get_text();
+    const OUString& rRepString = fixSpace(m_xReplaceED->get_text());
 
     bool bEnableNewReplace  = false;
     bool bEnableDelete      = false;
@@ -754,9 +767,9 @@ IMPL_LINK(SvxEditDictionaryDialog, ModifyHdl, weld::Entry&, 
rEdt, void)
             bEnableDelete = true;
         }
         bool bIsChange =
-                CDE_EQUAL != cmpDicEntry_Impl(m_xWordED->get_text(), aWordText)
-             || CDE_EQUAL != cmpDicEntry_Impl(m_xReplaceED->get_text(), 
aReplaceText);
-        if (!m_xWordED->get_text().isEmpty()  &&  bIsChange)
+                CDE_EQUAL != cmpDicEntry_Impl(fixSpace(m_xWordED->get_text()), 
aWordText)
+             || CDE_EQUAL != 
cmpDicEntry_Impl(fixSpace(m_xReplaceED->get_text()), aReplaceText);
+        if (!fixSpace(m_xWordED->get_text()).isEmpty() && bIsChange)
             bEnableNewReplace = true;
     }
 
@@ -765,10 +778,4 @@ IMPL_LINK(SvxEditDictionaryDialog, ModifyHdl, 
weld::Entry&, rEdt, void)
     m_xDeletePB->set_sensitive(bEnableDelete && !IsDicReadonly_Impl());
 }
 
-IMPL_STATIC_LINK(SvxEditDictionaryDialog, InsertTextHdl, OUString&, rText, 
bool)
-{
-    rText = rText.replaceAll(" ", "");
-    return true;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to