diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-02-05 22:27:14 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-02-06 10:30:08 +0100 |
commit | 1692bda118f234608ccec0697f9d7b6f6bd86b6d (patch) | |
tree | b8cabc4bbcd53b77266819a376bbcc2794a897f9 /sw/source | |
parent | 2113de51158a6e6c14931109bb9a4e27303c0eab (diff) |
tdf#115132: don't move out from current cell on Backspace/Delete
The behavior that cursor jumps out of current table box on Del/Backspace
introduced in commit 80a4b3b589a516392bcf1ad932619701eb95e250 is
not intuitive, and differs from what other word processors do.
Unit test included.
Change-Id: Icb53b6733f0d7394abe011fa067089e6693cf648
Reviewed-on: https://gerrit.libreoffice.org/49257
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/uibase/wrtsh/delete.cxx | 126 |
1 files changed, 63 insertions, 63 deletions
diff --git a/sw/source/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx index 4e0709342792..fc23a8237858 100644 --- a/sw/source/uibase/wrtsh/delete.cxx +++ b/sw/source/uibase/wrtsh/delete.cxx @@ -22,6 +22,7 @@ #include <editeng/lrspitem.hxx> #include <view.hxx> #include <drawbase.hxx> +#include <unobaseclass.hxx> inline void SwWrtShell::OpenMark() { @@ -195,6 +196,10 @@ long SwWrtShell::DelLeft() if( SwCursorShell::IsSttPara()) { + // Start/EndAllAction to avoid cursor flickering + UnoActionContext c(GetDoc()); + SwCursorShell::Push(); + // #i4032# Don't actually call a 'delete' if we // changed the table cell, compare DelRight(). const SwStartNode * pSNdOld = pWasInTableNd ? @@ -203,23 +208,34 @@ long SwWrtShell::DelLeft() // If the cursor is at the beginning of a paragraph, try to step // backwards. On failure we are done. - if( !SwCursorShell::Left(1,CRSR_SKIP_CHARS) ) - return 0; + bool bDoSomething = SwCursorShell::Left(1,CRSR_SKIP_CHARS); - // If the cursor entered or left a table (or both) we are done. No step - // back. - const SwTableNode* pIsInTableNd = SwCursorShell::IsCursorInTable(); - if( pIsInTableNd != pWasInTableNd ) - return 0; + if (bDoSomething) + { + // If the cursor entered or left a table (or both) we are done. + const SwTableNode* pIsInTableNd = SwCursorShell::IsCursorInTable(); + bDoSomething = pIsInTableNd == pWasInTableNd; - const SwStartNode* pSNdNew = pIsInTableNd ? - GetSwCursor()->GetNode().FindTableBoxStartNode() : - nullptr; + if (bDoSomething) + { + const SwStartNode* pSNdNew = pIsInTableNd ? + GetSwCursor()->GetNode().FindTableBoxStartNode() : + nullptr; - // #i4032# Don't actually call a 'delete' if we - // changed the table cell, compare DelRight(). - if ( pSNdOld != pSNdNew ) + // #i4032# Don't actually call a 'delete' if we + // changed the table cell, compare DelRight(). + bDoSomething = pSNdOld == pSNdNew; + } + } + + if (!bDoSomething) + { + // tdf#115132 Restore previous position and we are done + SwCursorShell::Pop(SwCursorShell::PopMode::DeleteCurrent); return 0; + } + + SwCursorShell::Pop(SwCursorShell::PopMode::DeleteStack); OpenMark(); SwCursorShell::Right(1,CRSR_SKIP_CHARS); @@ -283,8 +299,6 @@ long SwWrtShell::DelRight() if(nSelection & SelectionType::Text) nSelection = SelectionType::Text; - const SwTableNode * pWasInTableNd = nullptr; - switch( nSelection & ~SelectionType::Ornament ) { case SelectionType::PostIt: @@ -319,70 +333,56 @@ long SwWrtShell::DelRight() EnterStdMode(); } - pWasInTableNd = IsCursorInTable(); - - if( SelectionType::Text & nSelection && SwCursorShell::IsSttPara() && - SwCursorShell::IsEndPara() ) + if (SwCursorShell::IsEndPara()) { - // save cursor - SwCursorShell::Push(); + // Start/EndAllAction to avoid cursor flickering + UnoActionContext c(GetDoc()); + const SwTableNode* pWasInTableNd = IsCursorInTable(); + // #108049# Save the startnode of the current cell + const SwStartNode* pSNdOld = pWasInTableNd ? + GetSwCursor()->GetNode().FindTableBoxStartNode() : nullptr; + bool bCheckDelFull = SelectionType::Text & nSelection && SwCursorShell::IsSttPara(); bool bDelFull = false; - if ( SwCursorShell::Right(1,CRSR_SKIP_CHARS) ) + bool bDoNothing = false; + + // #i41424# Introduced a couple of + // Push()-Pop() pairs here. The reason for this is that a + // Right()-Left() combination does not make sure, that + // the cursor will be in its initial state, because there + // may be a numbering in front of the next paragraph. + SwCursorShell::Push(); + + if (SwCursorShell::Right(1, CRSR_SKIP_CHARS)) { - const SwTableNode * pCurrTableNd = IsCursorInTable(); - bDelFull = pCurrTableNd && pCurrTableNd != pWasInTableNd; + const SwTableNode* pCurrTableNd = IsCursorInTable(); + bDelFull = bCheckDelFull && pCurrTableNd && pCurrTableNd != pWasInTableNd; + if (!bDelFull && (IsCursorInTable() || (pCurrTableNd != pWasInTableNd))) + { + // #108049# Save the startnode of the current cell. + // May be different to pSNdOld as we have moved. + const SwStartNode* pSNdNew = pCurrTableNd ? + GetSwCursor()->GetNode().FindTableBoxStartNode() : nullptr; + + // tdf#115132 Only keep cursor position instead of deleting + // if we have moved to a different cell + bDoNothing = pSNdOld != pSNdNew; + } } // restore cursor SwCursorShell::Pop(SwCursorShell::PopMode::DeleteCurrent); - if( bDelFull ) + if (bDelFull) { DelFullPara(); UpdateAttr(); - break; } + if (bDelFull || bDoNothing) + break; } { - // #108049# Save the startnode of the current cell - const SwStartNode * pSNdOld; - pSNdOld = GetSwCursor()->GetNode().FindTableBoxStartNode(); - - if ( SwCursorShell::IsEndPara() ) - { - // #i41424# Introduced a couple of - // Push()-Pop() pairs here. The reason for this is that a - // Right()-Left() combination does not make sure, that - // the cursor will be in its initial state, because there - // may be a numbering in front of the next paragraph. - SwCursorShell::Push(); - - if ( SwCursorShell::Right(1, CRSR_SKIP_CHARS) ) - { - if (IsCursorInTable() || (pWasInTableNd != IsCursorInTable())) - { - /** #108049# Save the startnode of the current - cell. May be different to pSNdOld as we have - moved. */ - const SwStartNode * pSNdNew = GetSwCursor() - ->GetNode().FindTableBoxStartNode(); - - /** #108049# Only move instead of deleting if we - have moved to a different cell */ - if (pSNdOld != pSNdNew) - { - SwCursorShell::Pop(); - break; - } - } - } - - // restore cursor - SwCursorShell::Pop(SwCursorShell::PopMode::DeleteCurrent); - } - // If we are just ahead of a fieldmark, then remove it completely sw::mark::IFieldmark* pFm = GetCurrentFieldmark(); if (pFm && pFm->GetMarkStart() == *GetCursor()->GetPoint()) |