sw/qa/extras/layout/data/endOfLineComments.odt |binary sw/qa/extras/layout/layout2.cxx | 30 +++++++++++++++++++++++++ sw/source/core/text/itrcrsr.cxx | 10 +++++--- 3 files changed, 37 insertions(+), 3 deletions(-)
New commits: commit 63d8041c60c5d7c63dd34f94a694871b7ea9e2ca Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Thu Nov 12 09:56:37 2020 +0300 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Nov 18 08:03:56 2020 +0100 tdf120290 sw: move cursor behind comment at line end If the comment was the last item on the line, clicking the mouse button in the whitespace on the right did not place the cursor on the right side, but on the left side. For comments in the middle of a line, this change will mean that it will move behind the comment 1 unit earlier (1 TWIP I assume), but I would hope that wouldn't matter. This only works for the first comment for now. A followup commit will do this for multiple simultaneous comments, along with another edge case consisting a very thin portion. Change-Id: I49b15252441bc9e661644778dd417ef91f2447db Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105746 Tested-by: Justin Luth <justin_l...@sil.org> Reviewed-by: Justin Luth <justin_l...@sil.org> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/layout/data/endOfLineComments.odt b/sw/qa/extras/layout/data/endOfLineComments.odt new file mode 100644 index 000000000000..c58ea0fbe7fc Binary files /dev/null and b/sw/qa/extras/layout/data/endOfLineComments.odt differ diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx index 86bc9f43688c..e303cb2087b8 100644 --- a/sw/qa/extras/layout/layout2.cxx +++ b/sw/qa/extras/layout/layout2.cxx @@ -1881,6 +1881,36 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testImageComment) CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), aPosition.nContent.GetIndex()); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testCommentCursorPosition) +{ + // Load a document that has "aaa" in it, followed by three comments. + SwDoc* pDoc = createDoc("endOfLineComments.odt"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + SwRootFrame* pRoot = pWrtShell->GetLayout(); + CPPUNIT_ASSERT(pRoot->GetLower()->IsPageFrame()); + SwPageFrame* pPage = static_cast<SwPageFrame*>(pRoot->GetLower()); + CPPUNIT_ASSERT(pPage->GetLower()->IsBodyFrame()); + SwBodyFrame* pBody = static_cast<SwBodyFrame*>(pPage->GetLower()); + CPPUNIT_ASSERT(pBody->GetLower()->IsTextFrame()); + SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pBody->GetLower()); + + // Set a point in the whitespace past the end of the first line. + Point aPoint = pWrtShell->getShellCursor(false)->GetSttPos(); + aPoint.setX(aPoint.getX() + 10000); + + // Ask for the doc model pos of this layout point. + SwPosition aPosition(*pTextFrame->GetTextNodeForFirstText()); + pTextFrame->GetModelPositionForViewPoint(&aPosition, aPoint); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 4 (six would be even better...) + // - Actual : 3 + // i.e. the cursor got positioned before the first comment, + // so typing extended the comment instead of adding content after the comment. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), aPosition.nContent.GetIndex()); +} + CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf64222) { createDoc("tdf64222.docx"); diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx index 283116b50a06..7a6e1d3cdd03 100644 --- a/sw/source/core/text/itrcrsr.cxx +++ b/sw/source/core/text/itrcrsr.cxx @@ -1266,7 +1266,7 @@ void SwTextCursor::GetCharRect( SwRect* pOrig, TextFrameIndex const nOfst, */ static bool ConsiderNextPortionForCursorOffset(const SwLinePortion* pPor, sal_uInt16 nWidth30, sal_uInt16 nX) { - if (!pPor->GetNextPortion()) + if (!pPor->GetNextPortion() || pPor->IsBreakPortion()) { return false; } @@ -1275,10 +1275,14 @@ static bool ConsiderNextPortionForCursorOffset(const SwLinePortion* pPor, sal_uI // Exception: don't stop the iteration between as-char fly portions and their comments. if (nWidth30 >= nX && (!pPor->IsFlyCntPortion() || !pPor->GetNextPortion()->IsPostItsPortion())) { - return false; + // Normally returns false. + + // Another exception: If the cursor is at the very end of the portion, and the next portion is a comment, + // then place the cursor after the zero-width comment. This is primarily to benefit the very end of a line. + return nWidth30 == nX && pPor->GetNextPortion()->IsPostItsPortion(); } - return !pPor->IsBreakPortion(); + return true; } // Return: Offset in String _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits