summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt K <mattkse@gmail.com>2023-08-03 00:06:24 -0500
committerMike Kaganski <mike.kaganski@collabora.com>2023-11-10 19:05:13 +0100
commit0c3b89da7cde9866bf3174a6276736c76efb8356 (patch)
tree9c83facf9f05cd7a1dfb6c385370431fb2697e2e
parent87f0da8023081398d72372367db11d4a97d91833 (diff)
tdf#62603 Fix find/replace to not extend font attributes
This change modifies the logic of the core replace code to now not replace the 1st character and extend its attributes, but instead to actually replace characters to keep respective formatting. Additional checks are made for whether the replacement was shorter or longer than the found text, and to handle trimming or appending the final portions as needed. Change-Id: I03a5645898e55ad386bacc2766af9b244a97bd21 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155274 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--sw/source/core/txtnode/ndtxt.cxx28
1 files changed, 18 insertions, 10 deletions
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index af9b5f72fc92..541e3fd5049f 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -3849,19 +3849,27 @@ void SwTextNode::ReplaceText( const SwContentIndex& rStart, const sal_Int32 nDel
bool bOldExpFlg = IsIgnoreDontExpand();
SetIgnoreDontExpand( true );
- if (nLen && sInserted.getLength())
+ const sal_Int32 nInsLen = sInserted.getLength();
+ if (nLen && nInsLen)
{
- // Replace the 1st char, then delete the rest and insert.
- // This way the attributes of the 1st char are expanded!
- m_Text = m_Text.replaceAt(nStartPos, 1, sInserted.subView(0, 1));
+ m_Text = m_Text.replaceAt(nStartPos, nLen, sInserted);
- ++const_cast<SwContentIndex&>(rStart);
- m_Text = m_Text.replaceAt(rStart.GetIndex(), nLen - 1, u"");
- Update(rStart, nLen - 1, UpdateMode::Negative);
+ if (nLen > nInsLen) // short insert
+ {
+ // delete up to the point that the user specified
+ const SwContentIndex aNegIdx(rStart, nInsLen);
+ Update(aNegIdx, nLen - nInsLen, UpdateMode::Negative);
+ }
+ else if (nLen < nInsLen) // long insert
+ {
+ const SwContentIndex aIdx(rStart, nLen);
+ Update(aIdx, nInsLen - nLen, UpdateMode::Replace);
+ }
- std::u16string_view aTmpText( sInserted.subView(1) );
- m_Text = m_Text.replaceAt(rStart.GetIndex(), 0, aTmpText);
- Update(rStart, aTmpText.size(), UpdateMode::Replace);
+ for (sal_Int32 i = 0; i < nInsLen; i++)
+ {
+ ++const_cast<SwContentIndex&>(rStart);
+ }
}
else
{