sw/source/ui/docvw/edtwin.cxx | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-)
New commits: commit 148ed6783b3c6e5e3c068f1a802c8bdfaba14e21 Author: Caolán McNamara <caol...@redhat.com> Date: Fri Jan 31 23:36:02 2014 +0000 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 <fridr...@documentfoundation.org> Tested-by: Fridrich Strba <fridr...@documentfoundation.org> diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx index 2e981c4..7e978d0 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() ); } }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits