diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-10-07 17:46:36 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-10-09 10:15:39 +0200 |
commit | bfd4dd2c2cc3dfff5a5d3a32a5c9c4edf975f484 (patch) | |
tree | b724dd2658d2d4c4624f4b261f451d50195c208f /editeng | |
parent | 2a3b9af83b3ab2891d8d2257bf11e34f8f62e32b (diff) |
tdf#128009: Allow spaces in AutoText suggestions
Currently autotext entries with long names starting with spaces, or
containing spaces after first or second character, would never be
suggested when SvxAutoCorrCfg::IsAutoTextTip() gives true (set in
Tools -> AutoCorrect -> [x] Display remainder of name as suggestion
while typing), because only a single word no less than 3 chars long
left to cursor is considered a candidate for the name matching.
This change allows to consider multiple chunks of text left to the
cursor as the candidates for name matching. The chunks are 3-9
characters long, may start only between words, and have spaces,
including leading. Thus, AutoText entries with long names like
" Dr Foo" will now be suggested for an entry like "lorem dr f".
Change-Id: If91c957341a4f4b281acb0e4ada558706ea2f8c1
Reviewed-on: https://gerrit.libreoffice.org/80392
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/80495
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/misc/svxacorr.cxx | 57 |
1 files changed, 45 insertions, 12 deletions
diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index 0f06586be272..e79285ef616f 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -1543,12 +1543,12 @@ bool SvxAutoCorrect::AddWrtSttException( const OUString& rNew, return pLists && pLists->AddToWrdSttExceptList(rNew); } -bool SvxAutoCorrect::GetPrevAutoCorrWord( SvxAutoCorrDoc const & rDoc, - const OUString& rTxt, sal_Int32 nPos, - OUString& rWord ) const +OUString SvxAutoCorrect::GetPrevAutoCorrWord(SvxAutoCorrDoc const& rDoc, const OUString& rTxt, + sal_Int32 nPos) { + OUString sRet; if( !nPos ) - return false; + return sRet; sal_Int32 nEnde = nPos; @@ -1556,7 +1556,7 @@ bool SvxAutoCorrect::GetPrevAutoCorrWord( SvxAutoCorrDoc const & rDoc, if( ( nPos < rTxt.getLength() && !IsWordDelim( rTxt[ nPos ])) || IsWordDelim( rTxt[ --nPos ])) - return false; + return sRet; while( nPos && !IsWordDelim( rTxt[ --nPos ])) ; @@ -1569,21 +1569,54 @@ bool SvxAutoCorrect::GetPrevAutoCorrWord( SvxAutoCorrDoc const & rDoc, while( lcl_IsInAsciiArr( sImplSttSkipChars, rTxt[ nCapLttrPos ]) ) if( ++nCapLttrPos >= nEnde ) - return false; + return sRet; if( 3 > nEnde - nCapLttrPos ) - return false; + return sRet; const LanguageType eLang = GetDocLanguage( rDoc, nCapLttrPos ); - SvxAutoCorrect* pThis = const_cast<SvxAutoCorrect*>(this); - CharClass& rCC = pThis->GetCharClass( eLang ); + CharClass& rCC = GetCharClass( eLang ); if( lcl_IsSymbolChar( rCC, rTxt, nCapLttrPos, nEnde )) - return false; + return sRet; - rWord = rTxt.copy( nCapLttrPos, nEnde - nCapLttrPos ); - return true; + sRet = rTxt.copy( nCapLttrPos, nEnde - nCapLttrPos ); + return sRet; +} + +// static +std::vector<OUString> SvxAutoCorrect::GetChunkForAutoText(const OUString& rTxt, + const sal_Int32 nPos) +{ + constexpr sal_Int32 nMinLen = 3; + constexpr sal_Int32 nMaxLen = 9; + std::vector<OUString> aRes; + if (nPos >= nMinLen) + { + sal_Int32 nBegin = std::max<sal_Int32>(nPos - nMaxLen, 0); + // TODO: better detect word boundaries (not only whitespaces, but also e.g. punctuation) + if (nBegin > 0 && !IsWordDelim(rTxt[nBegin-1])) + { + while (nBegin + nMinLen <= nPos && !IsWordDelim(rTxt[nBegin])) + ++nBegin; + } + if (nBegin + nMinLen <= nPos) + { + OUString sRes = rTxt.copy(nBegin, nPos - nBegin); + aRes.push_back(sRes); + bool bLastStartedWithDelim = IsWordDelim(sRes[0]); + for (sal_Int32 i = 1; i <= sRes.getLength() - nMinLen; ++i) + { + bool bAdd = bLastStartedWithDelim; + bLastStartedWithDelim = IsWordDelim(sRes[i]); + bAdd = bAdd || bLastStartedWithDelim; + if (bAdd) + aRes.push_back(sRes.copy(i)); + } + } + } + return aRes; } bool SvxAutoCorrect::CreateLanguageFile( const LanguageTag& rLanguageTag, bool bNewFile ) |