summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2019-11-12 14:25:15 +0100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2019-11-13 01:25:26 +0100
commita80aef24826a7c3787fe6f66ea77cbf9699d6060 (patch)
tree5f4b57534a2e629a71d3a2f3c74122aad10b08be /sw
parent070b4c979ae1cb16be1a35d60a06db88fd97b770 (diff)
sw: avoid partial expansion of bookmark over new fieldmark
The comment that was added with commit 71f13a801608538f56a0cb2bce07a03faa5856f6 "#i29942# SwTxtNode::Update for bookmarks fixed. Bookmarks no longer grow on either side." suggests not to expand bookmarks in any case but in case the start and end position was the same, the start position was still moved so the mark expanded anyway. Unfortunately meanwhile commit c91024891ff10c2ae01e11a28a9aecca2f36b6c3 "tdf#96479 workaround bookmark end pos handling when inserting text into a text node." added a requirement that bookmarks with start==end *are* expanded. For the case where a new field is inserted, shortcut the insertion to do only one InsertString call so that any expansion of bookmarks will expand it over the entire field, not just its CH_TXT_ATR_FIELDSTART. Change-Id: If2608c9cf34a217330156e7ea566dcf528890c45 Reviewed-on: https://gerrit.libreoffice.org/82521 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sw')
-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;
}