sw/qa/extras/uiwriter/uiwriter3.cxx | 35 +++++++++++++++++++++++++++++++++++ sw/source/core/crsr/crsrsh.cxx | 1 + 2 files changed, 36 insertions(+)
New commits: commit 78fb5e63a4c4832181b92550df567e9b9fd56ba6 Author: Justin Luth <jl...@mail.com> AuthorDate: Thu Dec 7 14:39:08 2023 -0500 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Dec 12 08:22:41 2023 +0100 tdf#111969 sw: acknowledge that last half-character is in selection Wow, wrong since initial import and no one has touched it yet. This is not obscure code - it is called on most right mouse clicks and various other places. Kinda scary to make a change here... This unit test is copied from testCreateTextRangeByPixelPosition. Hopefully this pixel code is stable enough for unit tests... m_bPosMatchesBounds was introduced with commit cc63f3f550be4c8fe22cc8c6ff874812eefae20e Author: Vladimir Glazounov on Thu Apr 17 09:08:37 2003 +0000 make CppunitTest_sw_uiwriter3 \ CPPUNIT_TEST_NAME=testTdf111969_lastHalfcharOfSelection Change-Id: Ia2bcb93e390d14c9b4c1ab8a7059c41ed1b92429 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160442 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index 3027c65855ed..0ad197bf1198 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -2371,6 +2371,41 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf104649) CPPUNIT_ASSERT_EQUAL(OUString("Test"), getParagraph(1)->getString()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf111969_lastHalfcharOfSelection) +{ + // Given a document with a selected character, + // the last half of the character should also be considered to be "in the selection" + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + // move the cursor after the "o" (this is better/safer than testing cursor at end of paragrah) + pWrtShell->Insert2("Hello!"); + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + // get last pixel that will be part of the selection (current position 1pt wide). + Point aLogicL(pWrtShell->GetCharRect().Center()); + // cursor pos WOULD be in the selection, but just reduce by one for good measure... + aLogicL.AdjustX(-1); + // sanity check - pixel after should NOT be in the selection + Point aLogicR(pWrtShell->GetCharRect().Center()); + aLogicR.AdjustX(1); + SwRect aStartRect; + SwRect aEndRect; + //now select the letter 'o' + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + + // sanity check - the selection really does contain (or not) the two logic points + pWrtShell->GetCursor_()->FillStartEnd(aStartRect, aEndRect); + SwRect aSel(aStartRect.TopLeft(), aEndRect.BottomRight()); + CPPUNIT_ASSERT(aSel.Contains(aLogicL)); + CPPUNIT_ASSERT(!aSel.Contains(aLogicR)); + + // the pixel just at the end of the selection is considered to be in ModelPositionForViewPoint + CPPUNIT_ASSERT(pWrtShell->TestCurrPam(aLogicL)); + // the pixel just past the end of the selection is not considered to be inside. + CPPUNIT_ASSERT(!pWrtShell->TestCurrPam(aLogicR)); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf134931) { createSwDoc("tdf134931.odt"); diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx index 04b263cda754..c29020615058 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -1292,6 +1292,7 @@ bool SwCursorShell::TestCurrPam( SwCursorMoveState aTmpState( CursorMoveState::NONE ); aTmpState.m_bSetInReadOnly = IsReadOnlyAvailable(); + aTmpState.m_bPosMatchesBounds = true; // treat last half of character same as first half if ( !GetLayout()->GetModelPositionForViewPoint( &aPtPos, aPt, &aTmpState ) && bTstHit ) return false;