summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/source/core/crsr/bookmrk.cxx27
-rw-r--r--sw/source/core/txtnode/ndtxt.cxx7
2 files changed, 24 insertions, 10 deletions
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 7e514b7e18da..a16713dc295d 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -158,24 +158,35 @@ namespace
SwPosition const*const pSepPos)
{
io_pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::UI_REPLACE, nullptr);
+ OUString startChar(aStartMark);
+ if (aEndMark != CH_TXT_ATR_FORMELEMENT
+ && pField->GetMarkStart() == pField->GetMarkEnd())
+ {
+ // do only 1 InsertString call - to expand existing bookmarks at the
+ // position over the whole field instead of just aStartMark
+ startChar += OUStringChar(CH_TXT_ATR_FIELDSEP) + OUStringChar(aEndMark);
+ }
SwPosition start = pField->GetMarkStart();
if (aEndMark != CH_TXT_ATR_FORMELEMENT)
{
SwPaM aStartPaM(start);
- io_pDoc->getIDocumentContentOperations().InsertString(aStartPaM, OUString(aStartMark));
- --start.nContent; // restore, it was moved by InsertString
+ io_pDoc->getIDocumentContentOperations().InsertString(aStartPaM, startChar);
+ start.nContent -= startChar.getLength(); // restore, it was moved by InsertString
// do not manipulate via reference directly but call SetMarkStartPos
// which works even if start and end pos were the same
pField->SetMarkStartPos( start );
SwPosition& rEnd = pField->GetMarkEnd(); // note: retrieve after
// setting start, because if start==end it can go stale, see SetMarkPos()
assert(pSepPos == nullptr || (start < *pSepPos && *pSepPos <= rEnd));
- *aStartPaM.GetPoint() = pSepPos ? *pSepPos : rEnd;
- io_pDoc->getIDocumentContentOperations().InsertString(aStartPaM, OUString(CH_TXT_ATR_FIELDSEP));
- if (!pSepPos || rEnd < *pSepPos)
- { // rEnd is not moved automatically if it's same as insert pos
- ++rEnd.nContent;
+ if (startChar.getLength() == 1)
+ {
+ *aStartPaM.GetPoint() = pSepPos ? *pSepPos : rEnd;
+ io_pDoc->getIDocumentContentOperations().InsertString(aStartPaM, OUString(CH_TXT_ATR_FIELDSEP));
+ if (!pSepPos || rEnd < *pSepPos)
+ { // rEnd is not moved automatically if it's same as insert pos
+ ++rEnd.nContent;
+ }
}
assert(pSepPos == nullptr || (start < *pSepPos && *pSepPos <= rEnd));
}
@@ -185,7 +196,7 @@ namespace
}
SwPosition& rEnd = pField->GetMarkEnd();
- if (aEndMark)
+ if (aEndMark && startChar.getLength() == 1)
{
SwPaM aEndPaM(rEnd);
io_pDoc->getIDocumentContentOperations().InsertString(aEndPaM, OUString(aEndMark));
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index e39432ca13a4..6adb0a93dcf6 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -1386,8 +1386,9 @@ void SwTextNode::Update(
}
}
- // Bookmarks must never grow to either side, when editing (directly) to the left or right (#i29942#)!
- // And a bookmark with same start and end must remain to the left of the inserted text (used in XML import).
+ // Bookmarks must never grow to either side, when editing (directly)
+ // to the left or right (i#29942)! Exception: if the bookmark has
+ // 2 positions and start == end, then expand it (tdf#96479)
{
bool bAtLeastOneBookmarkMoved = false;
bool bAtLeastOneExpandedBookmarkAtInsertionPosition = false;
@@ -1412,6 +1413,8 @@ void SwTextNode::Update(
{ // don't switch to iterating aTmpIdxReg!
next = rEndIdx.GetNext();
}
+ // tdf#96479: if start == end, ignore the other position
+ // so it is moved!
rEndIdx.Assign( &aTmpIdxReg, rEndIdx.GetIndex() );
bAtLeastOneBookmarkMoved = true;
}