summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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