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>
This commit is contained in:
Mike Kaganski 2024-11-11 16:41:28 +05:00
parent 92618090a3
commit a9ac0a7f6c
2 changed files with 12 additions and 10 deletions

View file

@ -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 & );

View file

@ -235,15 +235,17 @@ void SwInsFootNoteDlg::Init()
else
m_xEndNoteBtn->set_active(true);
bool bNext = 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;
if (bNext)
m_rSh.GotoPrevFootnoteAnchor();
bool bPrev = m_rSh.GotoPrevFootnoteAnchor();
if (bPrev)
m_rSh.GotoNextFootnoteAnchor();
test = SwCursor(anchorPos, nullptr);
bool bPrev = test.GotoPrevFootnoteAnchor() && *test.GetPoint() != anchorPos;
m_xPrevBT->set_sensitive(bPrev);
m_xNextBT->set_sensitive(bNext);