summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2019-10-11 14:06:25 +0200
committerMichael Stahl <michael.stahl@cib.de>2019-10-23 13:02:14 +0200
commit6851182cb61a70d3ebd6ee098e8ba5f23582b352 (patch)
tree73d6acc926b38435bcd9b4332829b055260508cf
parentf610f9b611fe9f206b872ed06f7e859d688385fc (diff)
sw: SwWrtShell: delete field command when deleting the field
Change-Id: I6dbb7a36bdca103d6e9e72a5b5b48ffc135080a1 Reviewed-on: https://gerrit.libreoffice.org/80676 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--sw/inc/IDocumentMarkAccess.hxx2
-rw-r--r--sw/source/core/doc/docbm.cxx15
-rw-r--r--sw/source/uibase/wrtsh/delete.cxx10
3 files changed, 25 insertions, 2 deletions
diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx
index 1e2db2436a61..a076a6dada66 100644
--- a/sw/inc/IDocumentMarkAccess.hxx
+++ b/sw/inc/IDocumentMarkAccess.hxx
@@ -343,6 +343,8 @@ class IDocumentMarkAccess
static SW_DLLPUBLIC OUString GetCrossRefHeadingBookmarkNamePrefix();
static SW_DLLPUBLIC bool IsLegalPaMForCrossRefHeadingBookmark( const SwPaM& rPaM );
+ static void DeleteFieldmarkCommand(::sw::mark::IFieldmark const& rMark);
+
protected:
virtual ~IDocumentMarkAccess() {};
};
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 88a6019251b4..4f94baab5c90 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -530,6 +530,17 @@ bool IDocumentMarkAccess::IsLegalPaMForCrossRefHeadingBookmark( const SwPaM& rPa
rPaM.End()->nContent.GetIndex() == rPaM.End()->nNode.GetNode().GetTextNode()->Len() ) );
}
+void IDocumentMarkAccess::DeleteFieldmarkCommand(::sw::mark::IFieldmark const& rMark)
+{
+ if (GetType(rMark) != MarkType::TEXT_FIELDMARK)
+ {
+ return; // TODO FORMDATE has no command?
+ }
+ SwPaM pam(sw::mark::FindFieldSep(rMark), rMark.GetMarkStart());
+ ++pam.GetPoint()->nContent; // skip CH_TXT_ATR_FIELDSTART
+ pam.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(pam);
+}
+
namespace sw { namespace mark
{
MarkManager::MarkManager(SwDoc& rDoc)
@@ -1104,6 +1115,10 @@ namespace sw { namespace mark
}
virtual ~LazyFieldmarkDeleter() override
{
+ // note: because of the call chain from SwUndoDelete, the field
+ // command *cannot* be deleted here as it would create a separate
+ // SwUndoDelete that's interleaved with the SwHistory of the outer
+ // one - only delete the CH_TXT_ATR_FIELD*!
m_pFieldmark->ReleaseDoc(m_pDoc);
}
};
diff --git a/sw/source/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx
index cbb3fad91b69..4a2420ad7b84 100644
--- a/sw/source/uibase/wrtsh/delete.cxx
+++ b/sw/source/uibase/wrtsh/delete.cxx
@@ -239,10 +239,13 @@ bool SwWrtShell::DelLeft()
const SwPosition* pCurPos = GetCursor()->GetPoint();
SwPosition aPrevChar(*pCurPos);
--aPrevChar.nContent;
- sw::mark::IFieldmark* pFm = getIDocumentMarkAccess()->getFieldmarkFor(aPrevChar);
+ sw::mark::IFieldmark* pFm = getIDocumentMarkAccess()->getFieldmarkAt(aPrevChar);
if (pFm && pFm->GetMarkEnd() == *pCurPos)
{
+ mxDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr);
+ IDocumentMarkAccess::DeleteFieldmarkCommand(*pFm);
getIDocumentMarkAccess()->deleteMark(pFm);
+ mxDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::EMPTY, nullptr);
return true;
}
@@ -375,10 +378,13 @@ bool SwWrtShell::DelRight()
{
// If we are just ahead of a fieldmark, then remove it completely
- sw::mark::IFieldmark* pFm = GetCurrentFieldmark();
+ sw::mark::IFieldmark *const pFm = getIDocumentMarkAccess()->getFieldmarkAt(*GetCursor()->GetPoint());
if (pFm && pFm->GetMarkStart() == *GetCursor()->GetPoint())
{
+ mxDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr);
+ IDocumentMarkAccess::DeleteFieldmarkCommand(*pFm);
getIDocumentMarkAccess()->deleteMark(pFm);
+ mxDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::EMPTY, nullptr);
bRet = true;
break;
}