sw/source/uibase/docvw/edtwin.cxx | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
New commits: commit aac9bd235e65b27faf63e64bba3ecd94837381d6 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Fri Mar 4 20:05:03 2022 +0100 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Mon Mar 7 13:35:27 2022 +0100 sw_redlinehide: fix crashes in SwEditWin Surrounding functions These foolish functions write into the shell cursor! But the shell cursor's node isn't necessarily the same as before with merged paragraphs, so could crash with out of bounds indexes. Better use Push()/Pop(). Change-Id: I4fd0e2aa915b6c5448772a2c766848607bbf5aaa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131041 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index 84c99e8049c0..f40e530a0ae2 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -6451,9 +6451,7 @@ OUString SwEditWin::GetSurroundingText() const { bool bUnLockView = !rSh.IsViewLocked(); rSh.LockView(true); - - SwPosition *pPos = rSh.GetCursor()->GetPoint(); - const sal_Int32 nPos = pPos->nContent.GetIndex(); + rSh.Push(); // get the sentence around the cursor rSh.HideCursor(); @@ -6462,8 +6460,7 @@ OUString SwEditWin::GetSurroundingText() const rSh.GoEndSentence(); rSh.GetSelectedText( sReturn, ParaBreakType::ToOnlyCR ); - pPos->nContent = nPos; - rSh.ClearMark(); + rSh.Pop(SwCursorShell::PopMode::DeleteCurrent); rSh.HideCursor(); if (bUnLockView) @@ -6495,13 +6492,13 @@ Selection SwEditWin::GetSurroundingTextSelection() const // around the visible cursor. SwPosition *pPos = rSh.GetCursor()->GetPoint(); const sal_Int32 nPos = pPos->nContent.GetIndex(); + rSh.Push(); rSh.HideCursor(); rSh.GoStartSentence(); const sal_Int32 nStartPos = rSh.GetCursor()->GetPoint()->nContent.GetIndex(); - pPos->nContent = nPos; - rSh.ClearMark(); + rSh.Pop(SwCursorShell::PopMode::DeleteCurrent); rSh.ShowCursor(); if (bUnLockView) @@ -6523,14 +6520,11 @@ bool SwEditWin::DeleteSurroundingText(const Selection& rSelection) // rSelection is relative to the start of the sentence, so find that and // adjust the range by it - SwPosition *pPos = rSh.GetCursor()->GetPoint(); - const sal_Int32 nPos = pPos->nContent.GetIndex(); - + rSh.Push(); rSh.HideCursor(); rSh.GoStartSentence(); const sal_Int32 nStartPos = rSh.GetCursor()->GetPoint()->nContent.GetIndex(); - pPos->nContent = nPos; - rSh.ClearMark(); + rSh.Pop(SwCursorShell::PopMode::DeleteCurrent); rSh.ShowCursor(); if (rSh.SelectText(nStartPos + rSelection.Min(), nStartPos + rSelection.Max()))