sw/inc/crsrsh.hxx | 11 +++++++-- sw/qa/extras/uiwriter/uiwriter.cxx | 6 ++--- sw/source/core/crsr/crstrvl.cxx | 41 +++++++++++++++++++++++++++++++++-- sw/source/uibase/docvw/edtwin.cxx | 14 +++++------ sw/source/uibase/shells/textfld.cxx | 2 - sw/source/uibase/uitest/uiobject.cxx | 25 +++++++++++++++++---- 6 files changed, 80 insertions(+), 19 deletions(-)
New commits: commit 9a823863f7cc0499282cd62f782437d9e5012187 Author: Michael Stahl <[email protected]> AuthorDate: Fri Mar 4 21:53:38 2022 +0100 Commit: Thorsten Behrens <[email protected]> CommitDate: Fri Mar 18 18:36:43 2022 +0100 sw_redlinehide: more issues with SwEditWin Surrounding functions .. and SwEditWinUIObject. These need to work with TextFrameIndex. Add some functions to SwCursorShell to make it possible. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131042 Tested-by: Jenkins Reviewed-by: Michael Stahl <[email protected]> (cherry picked from commit 112592ac580108998a2cd99ae9bbf376c80c10d8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131109 Reviewed-by: Thorsten Behrens <[email protected]> (cherry picked from commit 26830d91d2f2a2d50f989fa3f36d18d55ea0eafd) Change-Id: I884c4822a0e7ecf254ea09a893762e1e6d539534 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131625 Tested-by: Thorsten Behrens <[email protected]> Reviewed-by: Thorsten Behrens <[email protected]> diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx index 23b3753dd938..2fa79345b240 100644 --- a/sw/inc/crsrsh.hxx +++ b/sw/inc/crsrsh.hxx @@ -26,6 +26,9 @@ #include <vcl/keycod.hxx> #include <o3tl/typed_flags_set.hxx> +#ifdef SW_DLLIMPLEMENTATION +#include <TextFrameIndex.hxx> +#endif #include "IShellCursorSupplier.hxx" #include "swdllapi.h" #include "docary.hxx" @@ -792,8 +795,12 @@ public: bool GotoINetAttr( const SwTextINetFormat& rAttr ); const SwFormatINetFormat* FindINetAttr( const OUString& rName ) const; - bool SelectText( const sal_Int32 nStart, - const sal_Int32 nEnd ); + bool SelectTextModel(sal_Int32 nStart, sal_Int32 nEnd); +#ifdef SW_DLLIMPLEMENTATION + bool SelectTextView(TextFrameIndex nStart, TextFrameIndex nEnd); + // result is only valid while cursor isn't moved! + TextFrameIndex GetCursorPointAsViewIndex() const; +#endif bool CheckTableBoxContent( const SwPosition* pPos = nullptr ); void SaveTableBoxContent( const SwPosition* pPos = nullptr ); diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 252e43bb4e24..74ad9b9c3c14 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -3831,7 +3831,7 @@ void SwUiWriterTest::testUndoDelAsCharTdf107512() CPPUNIT_ASSERT(rIDCO.InsertGraphicObject(*pShell->GetCursor(), grf, &frameSet, &grfSet)); CPPUNIT_ASSERT_EQUAL(size_t(2), pDoc->GetFlyCount(FLYCNTTYPE_GRF)); SvxCharHiddenItem hidden(true, RES_CHRATR_HIDDEN); - pShell->SelectText(1, 4); + pShell->SelectTextModel(1, 4); rIDCO.InsertPoolItem(*pShell->GetCursor(), hidden); // now we have "\1foo\1" with the "foo" hidden CPPUNIT_ASSERT(pShell->GetCursor()->GetNode().GetTextNode()->GetTextAttrForCharAt(0, RES_TXTATR_FLYCNT)); @@ -3845,7 +3845,7 @@ void SwUiWriterTest::testUndoDelAsCharTdf107512() query.ClearItem(RES_CHRATR_HIDDEN); // delete from the start - pShell->SelectText(0, 4); + pShell->SelectTextModel(0, 4); rIDCO.DeleteAndJoin(*pShell->GetCursor()); CPPUNIT_ASSERT(pShell->GetCursor()->GetNode().GetTextNode()->GetTextAttrForCharAt(0, RES_TXTATR_FLYCNT)); CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF)); @@ -3888,7 +3888,7 @@ void SwUiWriterTest::testUndoDelAsCharTdf107512() query.ClearItem(RES_CHRATR_HIDDEN); // delete from the end - pShell->SelectText(1, 5); + pShell->SelectTextModel(1, 5); rIDCO.DeleteAndJoin(*pShell->GetCursor()); CPPUNIT_ASSERT(pShell->GetCursor()->GetNode().GetTextNode()->GetTextAttrForCharAt(0, RES_TXTATR_FLYCNT)); CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc->GetFlyCount(FLYCNTTYPE_GRF)); diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx index 7df0ce6ff323..2d5898d7f51e 100644 --- a/sw/source/core/crsr/crstrvl.cxx +++ b/sw/source/core/crsr/crstrvl.cxx @@ -1930,7 +1930,7 @@ bool SwContentAtPos::IsInRTLText()const return bRet; } -bool SwCursorShell::SelectText( const sal_Int32 nStart, +bool SwCursorShell::SelectTextModel( const sal_Int32 nStart, const sal_Int32 nEnd ) { SET_CURR_SHELL( this ); @@ -1954,6 +1954,43 @@ bool SwCursorShell::SelectText( const sal_Int32 nStart, return bRet; } +TextFrameIndex SwCursorShell::GetCursorPointAsViewIndex() const +{ + SwPosition const*const pPos(GetCursor()->GetPoint()); + SwTextNode const*const pTextNode(pPos->nNode.GetNode().GetTextNode()); + assert(pTextNode); + SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pTextNode->getLayoutFrame(GetLayout()))); + assert(pFrame); + return pFrame->MapModelToViewPos(*pPos); +} + +bool SwCursorShell::SelectTextView(TextFrameIndex const nStart, + TextFrameIndex const nEnd) +{ + CurrShell aCurr( this ); + bool bRet = false; + + SwCallLink aLk( *this ); + SwCursorSaveState aSaveState( *m_pCurrentCursor ); + + SwPosition& rPos = *m_pCurrentCursor->GetPoint(); + m_pCurrentCursor->DeleteMark(); + // indexes must correspond to cursor point! + SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(m_pCurrentCursor->GetPoint()->nNode.GetNode().GetTextNode()->getLayoutFrame(GetLayout()))); + assert(pFrame); + rPos = pFrame->MapViewToModelPos(nStart); + m_pCurrentCursor->SetMark(); + rPos = pFrame->MapViewToModelPos(nEnd); + + if (!m_pCurrentCursor->IsSelOvr()) + { + UpdateCursor(); + bRet = true; + } + + return bRet; +} + bool SwCursorShell::SelectTextAttr( sal_uInt16 nWhich, bool bExpand, const SwTextAttr* pTextAttr ) @@ -1977,7 +2014,7 @@ bool SwCursorShell::SelectTextAttr( sal_uInt16 nWhich, if( pTextAttr ) { const sal_Int32* pEnd = pTextAttr->End(); - bRet = SelectText( pTextAttr->GetStart(), ( pEnd ? *pEnd : pTextAttr->GetStart() + 1 ) ); + bRet = SelectTextModel(pTextAttr->GetStart(), (pEnd ? *pEnd : pTextAttr->GetStart() + 1)); } } return bRet; diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index 0887baca08ed..7714bdd772d3 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -3698,7 +3698,7 @@ void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt) // select content of Input Field, but exclude CH_TXT_ATR_INPUTFIELDSTART // and CH_TXT_ATR_INPUTFIELDEND rSh.SttSelect(); - rSh.SelectText( aFieldAtPos.pFndTextAttr->GetStart() + 1, + rSh.SelectTextModel( aFieldAtPos.pFndTextAttr->GetStart() + 1, *(aFieldAtPos.pFndTextAttr->End()) - 1 ); } // don't reset here any longer so that, in case through MouseMove @@ -3728,8 +3728,8 @@ void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt) // select content of Input Field, but exclude CH_TXT_ATR_INPUTFIELDSTART // and CH_TXT_ATR_INPUTFIELDEND rSh.SttSelect(); - rSh.SelectText( aFieldAtPos.pFndTextAttr->GetStart() + 1, - *(aFieldAtPos.pFndTextAttr->End()) - 1 ); + rSh.SelectTextModel( aFieldAtPos.pFndTextAttr->GetStart() + 1, + *(aFieldAtPos.pFndTextAttr->End()) - 1 ); } } @@ -6314,18 +6314,18 @@ Selection SwEditWin::GetSurroundingTextSelection() const { // Return the position of the visible cursor in the sentence // around the visible cursor. - SwPosition *pPos = rSh.GetCursor()->GetPoint(); - const sal_Int32 nPos = pPos->nContent.GetIndex(); + TextFrameIndex const nPos(rSh.GetCursorPointAsViewIndex()); + rSh.Push(); rSh.HideCursor(); rSh.GoStartSentence(); - const sal_Int32 nStartPos = rSh.GetCursor()->GetPoint()->nContent.GetIndex(); + TextFrameIndex const nStartPos(rSh.GetCursorPointAsViewIndex()); rSh.Pop(SwCursorShell::PopMode::DeleteCurrent); rSh.ShowCursor(); - return Selection( nPos - nStartPos, nPos - nStartPos ); + return Selection(sal_Int32(nPos - nStartPos), sal_Int32(nPos - nStartPos)); } } diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index 3d6a2edee1f2..83233f3fef11 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -199,7 +199,7 @@ void SwTextShell::ExecField(SfxRequest &rReq) SwCursorShell::GetTextFieldAtCursor(rSh.GetCursor(), true)))) { rSh.SttSelect(); - rSh.SelectText( + rSh.SelectTextModel( SwCursorShell::StartOfInputFieldAtPos( *(rSh.GetCursor()->Start()) ) + 1, SwCursorShell::EndOfInputFieldAtPos( *(rSh.GetCursor()->Start()) ) - 1 ); } diff --git a/sw/source/uibase/uitest/uiobject.cxx b/sw/source/uibase/uitest/uiobject.cxx index ecdfd68ad6a8..f44f2b5a70fb 100644 --- a/sw/source/uibase/uitest/uiobject.cxx +++ b/sw/source/uibase/uitest/uiobject.cxx @@ -13,6 +13,7 @@ #include <view.hxx> #include <wrtsh.hxx> #include <navipi.hxx> +#include <ndtxt.hxx> #include <sfx2/sidebar/Sidebar.hxx> #include <sfx2/viewfrm.hxx> @@ -89,14 +90,30 @@ void SwEditWinUIObject::execute(const OUString& rAction, { auto itr = rParameters.find("START_POS"); OUString aStartPos = itr->second; - sal_Int32 nStartPos = aStartPos.toInt32(); + TextFrameIndex const nStartPos(aStartPos.toInt32()); itr = rParameters.find("END_POS"); assert(itr != rParameters.end()); OUString aEndPos = itr->second; - sal_Int32 nEndPos = aEndPos.toInt32(); - - getWrtShell(mxEditWin).SelectText(nStartPos, nEndPos); + TextFrameIndex const nEndPos(aEndPos.toInt32()); + + auto & shell = getWrtShell(mxEditWin); + if (shell.GetCursor_()->GetPoint()->nNode.GetNode().GetTextNode()) + { + shell.Push(); + shell.MovePara(GoCurrPara, fnParaEnd); + TextFrameIndex const len(shell.GetCursorPointAsViewIndex()); + shell.Pop(SwCursorShell::PopMode::DeleteCurrent); + SAL_WARN_IF( + sal_Int32(nStartPos) < 0 || nStartPos > len || sal_Int32(nEndPos) < 0 || nEndPos > len, "sw.ui", + "SELECT START/END_POS " << sal_Int32(nStartPos) << ".." << sal_Int32(nEndPos) << " outside 0.." << sal_Int32(len)); + shell.SelectTextView( + std::clamp(nStartPos, TextFrameIndex(0), len), std::clamp(nEndPos, TextFrameIndex(0), len)); + } + else + { + SAL_WARN("sw.ui", "SELECT without SwTextNode"); + } } } else if (rAction == "SIDEBAR")
