summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2022-06-27 19:44:00 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2022-07-08 13:48:09 +0200
commit5b0e81d462577113acac788ae4945e1cc00cf753 (patch)
treea8b2c3a4374aed1490f97f4a9a44d9f186e47050
parent6dd0074e5e42467a7f82e363f67ca95d04466fa9 (diff)
sw: split HideFieldmarkCommands out of ExpandFields
The problem is that during ODF export, SwXTextPortion::getString() must return the content of the field command. Change-Id: I00f77056e286fefaca0f156dbc31b6569d9c816e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136512 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r--sw/inc/modeltoviewhelper.hxx5
-rw-r--r--sw/inc/ndtxt.hxx2
-rw-r--r--sw/source/core/edit/edlingu.cxx1
-rw-r--r--sw/source/core/tox/ToxTextGenerator.cxx2
-rw-r--r--sw/source/core/txtnode/modeltoviewhelper.cxx18
-rw-r--r--sw/source/core/txtnode/txtedt.cxx2
-rw-r--r--sw/source/core/unocore/unoport.cxx3
7 files changed, 26 insertions, 7 deletions
diff --git a/sw/inc/modeltoviewhelper.hxx b/sw/inc/modeltoviewhelper.hxx
index d9d32a80f11e..c045c2837184 100644
--- a/sw/inc/modeltoviewhelper.hxx
+++ b/sw/inc/modeltoviewhelper.hxx
@@ -72,11 +72,12 @@ enum class ExpandMode
HideDeletions = 0x0008,
/// do not expand to content, but replace with zwsp
ReplaceMode = 0x0010,
+ HideFieldmarkCommands = 0x0020,
};
namespace o3tl
{
- template<> struct typed_flags<ExpandMode> : is_typed_flags<ExpandMode, 0x001f> {};
+ template<> struct typed_flags<ExpandMode> : is_typed_flags<ExpandMode, 0x003f> {};
}
class ModelToViewHelper
@@ -127,7 +128,7 @@ public:
ModelToViewHelper(const SwTextNode &rNode, SwRootFrame const* pLayout,
// defaults are appropriate for spell/grammar checking
- ExpandMode eMode = ExpandMode::ExpandFields | ExpandMode::ExpandFootnote | ExpandMode::ReplaceMode);
+ ExpandMode eMode = ExpandMode::ExpandFields | ExpandMode::ExpandFootnote | ExpandMode::HideFieldmarkCommands | ExpandMode::ReplaceMode);
ModelToViewHelper() //pass through filter, view == model
{
}
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index 8007beff59cd..fd64aaa8158b 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -710,7 +710,7 @@ public:
const bool bWithNum = false,
const bool bAddSpaceAfterListLabelStr = false,
const bool bWithSpacesForLevel = false,
- const ExpandMode eAdditionalMode = ExpandMode::ExpandFootnote) const;
+ const ExpandMode eAdditionalMode = ExpandMode::ExpandFootnote | ExpandMode::HideFieldmarkCommands) const;
bool CopyExpandText( SwTextNode& rDestNd, const SwIndex* pDestIdx,
sal_Int32 nIdx, sal_Int32 nLen,
SwRootFrame const* pLayout,
diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx
index 14e3655e847a..3e3fe0a63d89 100644
--- a/sw/source/core/edit/edlingu.cxx
+++ b/sw/source/core/edit/edlingu.cxx
@@ -934,6 +934,7 @@ uno::Reference< XSpellAlternatives >
// TODO: this doesn't handle fieldmarks properly
ModelToViewHelper const aConversionMap(*pNode, GetLayout(),
ExpandMode::ExpandFields | ExpandMode::ExpandFootnote | ExpandMode::ReplaceMode
+ | ExpandMode::HideFieldmarkCommands
| (GetLayout()->IsHideRedlines() ? ExpandMode::HideDeletions : ExpandMode(0))
| (GetViewOptions()->IsShowHiddenChar() ? ExpandMode(0) : ExpandMode::HideInvisible));
auto const nBeginView(aConversionMap.ConvertToViewPosition(nBegin));
diff --git a/sw/source/core/tox/ToxTextGenerator.cxx b/sw/source/core/tox/ToxTextGenerator.cxx
index ddf378e40ab5..82adcbca628e 100644
--- a/sw/source/core/tox/ToxTextGenerator.cxx
+++ b/sw/source/core/tox/ToxTextGenerator.cxx
@@ -335,7 +335,7 @@ void ToxTextGenerator::GetAttributesForNode(
{
// note: this *must* use the same flags as SwTextNode::GetExpandText()
// or indexes will be off!
- ExpandMode eMode = ExpandMode::ExpandFields;
+ ExpandMode eMode = ExpandMode::ExpandFields | ExpandMode::HideFieldmarkCommands;
if (pLayout && pLayout->IsHideRedlines())
{
eMode |= ExpandMode::HideDeletions;
diff --git a/sw/source/core/txtnode/modeltoviewhelper.cxx b/sw/source/core/txtnode/modeltoviewhelper.cxx
index c7b67a043b9e..e5aec1b510be 100644
--- a/sw/source/core/txtnode/modeltoviewhelper.cxx
+++ b/sw/source/core/txtnode/modeltoviewhelper.cxx
@@ -106,7 +106,7 @@ ModelToViewHelper::ModelToViewHelper(const SwTextNode &rNode,
if (eMode & ExpandMode::HideDeletions)
SwScriptInfo::selectRedLineDeleted(rNode, aHiddenMulti);
- if (eMode & ExpandMode::ExpandFields)
+ if (eMode & ExpandMode::HideFieldmarkCommands)
{
// hide fieldmark commands
IDocumentMarkAccess const& rIDMA(*rNode.GetDoc().getIDocumentMarkAccess());
@@ -206,6 +206,22 @@ ModelToViewHelper::ModelToViewHelper(const SwTextNode &rNode,
aHiddenMulti.Select({*oStartHidden, rNode.Len() - 1}, true);
}
}
+ else if (eMode & ExpandMode::ExpandFields) // subset: only hide dummy chars
+ {
+ for (sal_Int32 i = 0; i < rNode.GetText().getLength(); ++i)
+ {
+ switch (rNode.GetText()[i])
+ {
+ case CH_TXT_ATR_FIELDSTART:
+ case CH_TXT_ATR_FIELDSEP:
+ case CH_TXT_ATR_FIELDEND:
+ {
+ aHiddenMulti.Select({i, i}, true);
+ break;
+ }
+ }
+ }
+ }
std::vector<block> aBlocks;
diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index e0ed33f30867..20d3e483408e 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -2085,7 +2085,7 @@ bool SwTextNode::CountWords( SwDocStat& rStat,
// ConversionMap to expand fields, remove invisible and redline deleted text for scanner
const ModelToViewHelper aConversionMap(*this,
getIDocumentLayoutAccess().GetCurrentLayout(),
- ExpandMode::ExpandFields | ExpandMode::ExpandFootnote | ExpandMode::HideInvisible | ExpandMode::HideDeletions);
+ ExpandMode::ExpandFields | ExpandMode::ExpandFootnote | ExpandMode::HideInvisible | ExpandMode::HideDeletions | ExpandMode::HideFieldmarkCommands);
const OUString& aExpandText = aConversionMap.getViewText();
if (aExpandText.isEmpty() && !bCountNumbering)
diff --git a/sw/source/core/unocore/unoport.cxx b/sw/source/core/unocore/unoport.cxx
index dd44538edbd1..fa8b93eb84de 100644
--- a/sw/source/core/unocore/unoport.cxx
+++ b/sw/source/core/unocore/unoport.cxx
@@ -169,7 +169,8 @@ OUString SwXTextPortion::getString()
{
const sal_Int32 nStt = rUnoCursor.Start()->nContent.GetIndex();
aText = pTextNd->GetExpandText(nullptr, nStt,
- rUnoCursor.End()->nContent.GetIndex() - nStt );
+ rUnoCursor.End()->nContent.GetIndex() - nStt,
+ false, false, false, ExpandMode::ExpandFootnote);
}
return aText;
}