diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-11-11 16:41:28 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-11-11 18:25:48 +0100 |
commit | a9ac0a7f6c8475d97480318ebd1fe35e964a8600 (patch) | |
tree | 90be9cecceb542445f83bbad1a3c1b8c23603ac6 | |
parent | 92618090a370c0f57be64d9f19cead2e87cc0d02 (diff) |
tdf#144717: fix SwInsFootNoteDlg's next/prev button state check
Trying to move the current cursor, which may actually be a selection,
to find next/prev footnore, may try to expand the selection across a
table boundary (from outside to inside), which would fail. This was
incorrectly treated as "there's no next/prev footnote, the cursor is
unchanged" case, and the cursor wasn't restored.
Use a separate local cursor object for testing; and make it at least
somewhat useful, to detect the case when there's no more footnotes
in the document, so the prev/next buttons would get disabled.
Change-Id: I7db100dfdd290fe01b3eebe17f1dec2784315243
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176399
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r-- | sw/inc/swcrsr.hxx | 4 | ||||
-rw-r--r-- | sw/source/ui/misc/insfnote.cxx | 20 |
2 files changed, 13 insertions, 11 deletions
diff --git a/sw/inc/swcrsr.hxx b/sw/inc/swcrsr.hxx index 2b424db27de0..0526eb04d892 100644 --- a/sw/inc/swcrsr.hxx +++ b/sw/inc/swcrsr.hxx @@ -181,8 +181,8 @@ public: bool GotoRegion( std::u16string_view rName ); SW_DLLPUBLIC bool GotoFootnoteAnchor(); bool GotoFootnoteText(); - bool GotoNextFootnoteAnchor(); - bool GotoPrevFootnoteAnchor(); + SW_DLLPUBLIC bool GotoNextFootnoteAnchor(); + SW_DLLPUBLIC bool GotoPrevFootnoteAnchor(); SW_DLLPUBLIC bool MovePara( SwWhichPara, SwMoveFnCollection const & ); bool MoveSection( SwWhichSection, SwMoveFnCollection const & ); diff --git a/sw/source/ui/misc/insfnote.cxx b/sw/source/ui/misc/insfnote.cxx index 4ddc4c1f9117..e4509d8fbaf9 100644 --- a/sw/source/ui/misc/insfnote.cxx +++ b/sw/source/ui/misc/insfnote.cxx @@ -235,15 +235,17 @@ void SwInsFootNoteDlg::Init() else m_xEndNoteBtn->set_active(true); - bool bNext = m_rSh.GotoNextFootnoteAnchor(); - - if (bNext) - m_rSh.GotoPrevFootnoteAnchor(); - - bool bPrev = m_rSh.GotoPrevFootnoteAnchor(); - - if (bPrev) - m_rSh.GotoNextFootnoteAnchor(); + // Do not move the shell cursor; move a collapsed SwCursor created in the correct position. + // Moving a cursor with a mark will attempt to move only the point, thus a selection from + // outside of a table to inside of it could be possible, which would fail. + // bNext and bPrev are only false (simultaneously) for single-footnote documents, because + // GotoNextFootnoteAnchor / GotoPrevFootnoteAnchor may wrap. + const auto anchorPos = *m_rSh.GetCursor()->GetPoint(); + SwCursor test(anchorPos, nullptr); + bool bNext = test.GotoNextFootnoteAnchor() && *test.GetPoint() != anchorPos; + + test = SwCursor(anchorPos, nullptr); + bool bPrev = test.GotoPrevFootnoteAnchor() && *test.GetPoint() != anchorPos; m_xPrevBT->set_sensitive(bPrev); m_xNextBT->set_sensitive(bNext); |