summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2023-05-09 21:51:10 +0200
committerLászló Németh <nemeth@numbertext.org>2023-05-10 09:54:13 +0200
commitb1568a4cd8b439de19aab2bfe5f8f8465e4dc6af (patch)
tree70a78d701450fec32ddd58b74347b4206321da6f
parent936ea5d2cc5267dc169a4dc5986d9ae604f14d81 (diff)
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 <nemeth@numbertext.org>
-rw-r--r--cui/source/options/optdict.cxx39
1 files changed, 23 insertions, 16 deletions
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: */