summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2014-01-31 23:36:02 +0000
committerFridrich Strba <fridrich@documentfoundation.org>2014-02-06 14:41:37 +0000
commit148ed6783b3c6e5e3c068f1a802c8bdfaba14e21 (patch)
tree3b1f525ab7fc59a792f4981336e04738f8c661d5
parentdd3b06fd0f6160730aace36f8287d9bc4bd81522 (diff)
fdo#61251 prefer exact matches before case guess matching
Change-Id: I3a7badf063110e78d53859381efba32837aa71bb (cherry picked from commit 8df7e6ced2c728932a07539c8607263d7298ab7b) Reviewed-on: https://gerrit.libreoffice.org/7883 Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org> Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
-rw-r--r--sw/source/ui/docvw/edtwin.cxx38
1 files changed, 32 insertions, 6 deletions
diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx
index 2e981c4e78ee..7e978d055bd8 100644
--- a/sw/source/ui/docvw/edtwin.cxx
+++ b/sw/source/ui/docvw/edtwin.cxx
@@ -283,7 +283,7 @@ struct QuickHelpData
// Fills internal structures with hopefully helpful information.
void FillStrArr( SwWrtShell& rSh, const OUString& rWord );
- void SortAndFilter();
+ void SortAndFilter(const OUString &rOrigWord);
};
/**
@@ -5850,6 +5850,11 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const OUString& rWord )
if( rStr.getLength() > rWord.getLength() &&
rCC.lowercase( rStr, 0, rWord.getLength() ) == sWordLower )
{
+ //fdo#61251 if it's an exact match, ensure unchanged replacement
+ //exists as a candidate
+ if (rStr.startsWith(rWord))
+ m_aHelpStrings.push_back(rStr);
+
if ( aWordCase == CASE_LOWER )
m_aHelpStrings.push_back( rCC.lowercase( rStr ) );
else if ( aWordCase == CASE_SENTENCE )
@@ -5878,6 +5883,10 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const OUString& rWord )
for (unsigned int i= 0; i<strings.size(); i++)
{
OUString aCompletedString = strings[i];
+ //fdo#61251 if it's an exact match, ensure unchanged replacement
+ //exists as a candidate
+ if (aCompletedString.startsWith(rWord))
+ m_aHelpStrings.push_back(aCompletedString);
if ( aWordCase == CASE_LOWER )
m_aHelpStrings.push_back( rCC.lowercase( aCompletedString ) );
else if ( aWordCase == CASE_SENTENCE )
@@ -5897,11 +5906,28 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const OUString& rWord )
namespace {
-struct CompareIgnoreCaseAscii
+class CompareIgnoreCaseAsciiFavorExact
+ : public std::binary_function<const OUString&, const OUString&, bool>
{
+ const OUString &m_rOrigWord;
+public:
+ CompareIgnoreCaseAsciiFavorExact(const OUString& rOrigWord)
+ : m_rOrigWord(rOrigWord)
+ {
+ }
+
bool operator()(const OUString& s1, const OUString& s2) const
{
- return s1.compareToIgnoreAsciiCase(s2) < 0;
+ int nRet = s1.compareToIgnoreAsciiCase(s2);
+ if (nRet == 0)
+ {
+ //fdo#61251 sort stuff that starts with the exact rOrigWord before
+ //another ignore-case candidate
+ int n1StartsWithOrig = s1.startsWith(m_rOrigWord) ? 0 : 1;
+ int n2StartsWithOrig = s2.startsWith(m_rOrigWord) ? 0 : 1;
+ return n1StartsWithOrig < n2StartsWithOrig;
+ }
+ return nRet < 0;
}
};
@@ -5916,11 +5942,11 @@ struct EqualIgnoreCaseAscii
} // anonymous namespace
// TODO Implement an i18n aware sort
-void QuickHelpData::SortAndFilter()
+void QuickHelpData::SortAndFilter(const OUString &rOrigWord)
{
std::sort( m_aHelpStrings.begin(),
m_aHelpStrings.end(),
- CompareIgnoreCaseAscii() );
+ CompareIgnoreCaseAsciiFavorExact(rOrigWord) );
std::vector<OUString>::iterator it = std::unique( m_aHelpStrings.begin(),
m_aHelpStrings.end(),
@@ -5957,7 +5983,7 @@ void SwEditWin::ShowAutoTextCorrectQuickHelp(
if( !m_pQuickHlpData->m_aHelpStrings.empty() )
{
- m_pQuickHlpData->SortAndFilter();
+ m_pQuickHlpData->SortAndFilter(rWord);
m_pQuickHlpData->Start( rSh, rWord.getLength() );
}
}