summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-05-06 15:21:45 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-05-06 16:38:53 +0200
commit71019ec15bd3fe15385443b68614fd2402e0040f (patch)
tree6c1f68ad226843abb18ac0b36906a8796d8c03fe /sw/source
parent40462e3e78e7beb7cd22c8825f473126d1c89ef8 (diff)
sw: don't copy useless char escapement to next node on split
Unless autocorrect notices such a just-typed content, pressing enter at the end of a paragraph which ends with superscript or subscript text will carry over that formatting to the next paragraph, which is hardly wanted by any user. Technically this is not copying: paragraph split works by creating a next text node, moving all content & formatting to this next node, then move part of the content back to the previous node, which is all content in case of an enter at the end of a paragraph. Copying character formatting over to the next text node makes sense: e.g. paragraph alignment or boldness is probably something a user wants to continue using in the next text node. But superscript is typically created by autocorrect in English text for "1st" and similar input, this is usually unwanted in the next paragraph. Fix the problem by special-casing the RES_CHRATR_ESCAPEMENT case and remove the matching SvxEscapementItem from the hints of the just created next paragraph in case it's there. A possible future improvement would be to support this when there are other active (direct formatting) hints, in which case going via SwDoc::ResetAttrs() is probably a better choice, but the effects of that for undo and redlining is not clear. Change-Id: I57feb99d9a31f16c277eba44f464ab49936b65aa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133936 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/txtnode/ndtxt.cxx31
1 files changed, 31 insertions, 0 deletions
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 591a75431cc9..d9905fce33cc 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -698,6 +698,37 @@ SwTextNode *SwTextNode::SplitContentNode(const SwPosition & rPos,
}
}
+ // pNode is the previous node, 'this' is the next node from the split.
+ if (nSplitPos == nTextLen && m_pSwpHints)
+ {
+ // We just created an empty next node: avoid unwanted superscript in the new node if it's
+ // there.
+ for (size_t i = 0; i < m_pSwpHints->Count(); ++i)
+ {
+ SwTextAttr* pHt = m_pSwpHints->Get(i);
+ if (pHt->Which() != RES_TXTATR_AUTOFMT)
+ {
+ continue;
+ }
+
+ const sal_Int32* pEnd = pHt->GetEnd();
+ if (!pEnd || pHt->GetStart() != *pEnd)
+ {
+ continue;
+ }
+
+ const std::shared_ptr<SfxItemSet>& pSet = pHt->GetAutoFormat().GetStyleHandle();
+ if (!pSet || pSet->Count() != 1 || !pSet->GetItem(RES_CHRATR_ESCAPEMENT))
+ {
+ continue;
+ }
+
+ m_pSwpHints->DeleteAtPos(i);
+ SwTextAttr::Destroy(pHt, GetDoc().GetAttrPool());
+ --i;
+ }
+ }
+
#ifndef NDEBUG
if (isHide) // otherwise flags won't be set anyway
{