diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2024-02-17 11:25:37 -0500 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2024-02-20 17:02:42 +0100 |
commit | 1b0f67018fa1d514ebca59e081efdd24c1d7811b (patch) | |
tree | bd27af759a44ebb5e1ca209397650078116ff0d7 /writerfilter/source/dmapper/DomainMapper_Impl.cxx | |
parent | 2567f58f20cdc38b6ed92c639c0fcb19af84295f (diff) |
docx import: correct redline content-controls
When inserting and deleting content-controls
with change-tracking enabled, we hit a few
corner-cases that we need to handle more
smartly.
First, we shouldn't redline the controls
themselves, just the placeholder text.
Second, we have to take special care
to create valid XML structure with
the redline tags.
Includes unit-test that reproduces the
issues and verifies that both saving
and loading work as expected.
Change-Id: I6af4d0d2c3f0661e7990d5414cc93effc96f0469
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163647
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'writerfilter/source/dmapper/DomainMapper_Impl.cxx')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 70b8f6d74554..73287b929f0c 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1014,7 +1014,40 @@ void DomainMapper_Impl::PopSdt() uno::Reference<text::XTextRange> xStart = aPosition.m_xTextRange; uno::Reference<text::XTextRange> xEnd = GetTopTextAppend()->getEnd(); uno::Reference<text::XText> xText = xEnd->getText(); - uno::Reference<text::XTextCursor> xCursor = xText->createTextCursorByRange(xStart); + + uno::Reference<text::XTextCursor> xCursor; + try + { + xCursor = xText->createTextCursorByRange(xStart); + } + catch (const uno::RuntimeException&) + { + // We redline form controls and that gets us confused when + // we process the SDT around the placeholder. What seems to + // happen is we lose the text-range when we pop the SDT position. + // Here, we reset the text-range when we fail to create the + // cursor from the top SDT position. + if (m_aTextAppendStack.empty()) + { + return; + } + + uno::Reference<text::XTextAppend> xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (!xTextAppend.is()) + { + return; + } + + uno::Reference<text::XText> xText2 = xTextAppend->getText(); + if (!xText2.is()) + { + return; + } + + // Reset to the start. + xCursor = xText2->createTextCursorByRange(xTextAppend->getStart()); + } + if (!xCursor) { SAL_WARN("writerfilter.dmapper", "DomainMapper_Impl::PopSdt: no start position"); |