summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2021-12-26 20:38:30 +0300
committerXisco Fauli <xiscofauli@libreoffice.org>2021-12-27 23:43:02 +0100
commit176266177ab810159a9956fc776b872ecba3355b (patch)
treebc0a0022611f4b427340342551039e6aad01ddd7 /sw/source
parente6b65a50ed745914ac16fb239a593581d3432173 (diff)
tdf#146257: sw: better handling for list numbering = NONE
Previously during refactoring were lost some corner cases with some level having disabled numbering. In this case LO should strip useless delimiters up to next level. For example, if second level has disabled numbering, third level should look like "1.1", but not "1..1". Change-Id: I259a16b456f51bc76d5c8360974d0acadfc36776 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127517 Tested-by: Jenkins Reviewed-by: Vasily Melenchuk <vasily.melenchuk@cib.de> (cherry picked from commit bf2b46aa15665dde63ceff4e7686b99b3990354f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127569 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/doc/number.cxx27
1 files changed, 26 insertions, 1 deletions
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index acb142b09988..93a5c149f15c 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -670,6 +670,21 @@ OUString SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVecto
const SwNumFormat& rMyNFormat = Get( o3tl::narrowing<sal_uInt16>(nLevel) );
+ if (rMyNFormat.GetNumberingType() == SVX_NUM_NUMBER_NONE)
+ {
+ if (!rMyNFormat.HasListFormat())
+ return OUString();
+
+ // If numbering is disabled for this level we should emit just prefix/suffix
+ // Remove everything between first %1% and last %n% (including markers)
+ OUString sLevelFormat = rMyNFormat.GetListFormat(bInclStrings);
+ sal_Int32 nFirstPosition = sLevelFormat.indexOf("%");
+ sal_Int32 nLastPosition = sLevelFormat.lastIndexOf("%");
+ if (nFirstPosition >= 0 && nLastPosition >= nFirstPosition)
+ sLevelFormat = sLevelFormat.replaceAt(nFirstPosition, nLastPosition - nFirstPosition + 1, u"");
+ return sLevelFormat;
+ }
+
css::lang::Locale aLocale( LanguageTag::convertToLocale(nLang));
if (rMyNFormat.HasListFormat())
@@ -681,9 +696,19 @@ OUString SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVecto
for (SwNumberTree::tNumberVector::size_type i=0; i <= nLevel; ++i)
{
OUString sReplacement;
- if (rMyNFormat.GetNumberingType() == SVX_NUM_NUMBER_NONE)
+ const SwNumFormat& rNFormat = Get(i);
+ if (rNFormat.GetNumberingType() == SVX_NUM_NUMBER_NONE)
{
// Numbering disabled - replacement is empty
+ // And we should skip all level string content until next level marker:
+ // so %1%.%2%.%3% with second level as NONE will result 1.1, not 1..1
+ OUString sFind("%" + OUString::number(i + 1) + "%");
+ sal_Int32 nPositionToken = sLevelFormat.indexOf(sFind);
+ sal_Int32 nPositionNextToken = sLevelFormat.indexOf('%', nPositionToken + sFind.getLength());
+ if (nPositionToken > 0 && nPositionNextToken >= nPositionToken)
+ {
+ sLevelFormat = sLevelFormat.replaceAt(nPositionToken, nPositionNextToken - nPositionToken, u"");
+ }
}
else if (rNumVector[i])
{