summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2020-11-12 09:56:37 +0300
committerMiklos Vajna <vmiklos@collabora.com>2020-11-18 08:03:56 +0100
commit63d8041c60c5d7c63dd34f94a694871b7ea9e2ca (patch)
treee807e75ef3b81176b36e4036d05e18792207d548
parentd9391396434a5ad93f6796248c255b5bb2f3cba7 (diff)
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_luth@sil.org> Reviewed-by: Justin Luth <justin_luth@sil.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/qa/extras/layout/data/endOfLineComments.odtbin0 -> 10823 bytes
-rw-r--r--sw/qa/extras/layout/layout2.cxx30
-rw-r--r--sw/source/core/text/itrcrsr.cxx10
3 files changed, 37 insertions, 3 deletions
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
--- /dev/null
+++ b/sw/qa/extras/layout/data/endOfLineComments.odt
Binary files 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