sw: compare positions, not pointers, when looking for a format redline

When a paragraph had a tracked format change before the selection,
formatting another author's tracked format change and rejecting the new
change kept the other author's formatting.

Since commit ee3171adb2 (tdf#143918 sw:
fix reject of multiple changes, 2021-08-19), lcl_SetRedline looked for
an existing redline over the range, and continued while
"pRStt <= rRg.Start()", which compared the addresses of the two
positions, not the positions themselves.

Compare the positions, and go on while the redline does not start after
the end of the range, because since commit
b5d0868ef42135beb0329ecb9302ce48b08fa2a8 (cool#15941 sw interdependent
redlines: fix creating a fmt on top of ins-then-fmt, 2026-06-17) a
redline inside the range counts as well.

For some reason, the added unit test fails without the fix only on
Windows; on Linux on my system, it passes without the fix.

Signed-off-by: Mike Kaganski <mike.kaganski@collabora.com>
Change-Id: I396567d8507e800fefcdc643a63ee6ad91b8b8ee
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/13802
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 2da0c4fa2e5284b25f0dca85243a1f8ef5e9506b)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211602
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Mike Kaganski
2026-09-30 12:20:44 +02:00
committed by Xisco Fauli
parent 984efa1ff7
commit e4efd9faf2
3 changed files with 55 additions and 1 deletions
+53
View File
@@ -620,6 +620,59 @@ CPPUNIT_TEST_FIXTURE(Test, testFormatThenFormatOther)
CPPUNIT_ASSERT_EQUAL(WEIGHT_NORMAL, aSet.Get(RES_CHRATR_WEIGHT).GetValue());
CPPUNIT_ASSERT_EQUAL(ITALIC_NONE, aSet.Get(RES_CHRATR_POSTURE).GetValue());
}
CPPUNIT_TEST_FIXTURE(Test, testFormatThenFormatAfterOtherFormat)
{
// Given a "<format>AAA</format> <format>BBB CCC DDD</format> EEE" document with bold format
// redlines authored by Alice:
createSwDoc("fmt-twice.docx");
SwDocShell* pDocShell = getSwDocShell();
SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
SwDoc* pDoc = pDocShell->GetDoc();
IDocumentRedlineAccess& rIDRA = pDoc->getIDocumentRedlineAccess();
SwRedlineTable& rRedlines = rIDRA.GetRedlineTable();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rRedlines.size());
CPPUNIT_ASSERT_EQUAL(u"Alice"_ustr, rRedlines[1]->GetAuthorString());
// When a different author selects the second range and applies italic:
SwModule* pModule = SwModule::get();
pModule->SetRedlineAuthor(u"Bob"_ustr);
comphelper::ScopeGuard g(
[pModule] { pModule->SetRedlineAuthor(SwResId(STR_REDLINE_UNKNOWN_AUTHOR)); });
pWrtShell->SttEndDoc(/*bStt=*/true);
// Skip "AAA ".
pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 4, /*bBasicCall=*/false);
// Select "BBB CCC DDD".
pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, 11, /*bBasicCall=*/false);
SwView& rView = pWrtShell->GetView();
{
SvxPostureItem aPostureItem(ITALIC_NORMAL, RES_CHRATR_POSTURE);
SfxItemSet aSet(
SfxItemSet::makeFixedSfxItemSet<RES_CHRATR_BEGIN, RES_CHRATR_END>(rView.GetPool()));
aSet.Put(aPostureItem);
pWrtShell->SetAttrSet(aSet);
}
// Then make sure Bob's redline replaced Alice's on "BBB CCC DDD":
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rRedlines.size());
CPPUNIT_ASSERT_EQUAL(u"Bob"_ustr, rRedlines[1]->GetAuthorString());
// And when rejecting Bob's redline:
pWrtShell->RejectRedline(1, /*bDirect=*/false);
// Then make sure both Alice's bold and Bob's italic are gone from "BBB CCC DDD":
pWrtShell->SttEndDoc(/*bStt=*/true);
pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 5, /*bBasicCall=*/false);
SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_CHRATR_POSTURE, RES_CHRATR_WEIGHT>(
pDoc->GetAttrPool()));
pWrtShell->GetCurAttr(aSet);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 5 (WEIGHT_NORMAL)
// - Actual : 8 (WEIGHT_BOLD)
// i.e. Alice's bold survived the reject.
CPPUNIT_ASSERT_EQUAL(WEIGHT_NORMAL, aSet.Get(RES_CHRATR_WEIGHT).GetValue());
CPPUNIT_ASSERT_EQUAL(ITALIC_NONE, aSet.Get(RES_CHRATR_POSTURE).GetValue());
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Binary file not shown.
@@ -1293,7 +1293,8 @@ namespace //local functions originally from docfmt.cxx
}
}
}
} while( pRStt <= rRg.Start() && ++nRedlPos < rDoc.getIDocumentRedlineAccess().GetRedlineTable().size());
} while (*pRStt <= *rRg.End()
&& ++nRedlPos < rDoc.getIDocumentRedlineAccess().GetRedlineTable().size());
}
if (!xExtra && bExistingFormatRedlineAtRange)
{