From c9fefd5a2cf5eb97fb23279e5b5e2f4c3a19b22e Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 8 Jun 2017 11:35:05 +0200 Subject: [PATCH] Fix bad cursor positioning when entering an inset The test added at 359aef92 was incorrect. Actually, Inset::editXY returns the inset when it is edited and also when it is not, which can be confusing. So if we are unlucky and the slices positions in the text area and in the inner inset match, the code below triggers and many bad things can happen. Also improve the documentation of Inset::editXY and TextMetrics::editXY. Fixes #10691. --- src/TextMetrics.cpp | 4 +++- src/TextMetrics.h | 4 +++- src/insets/Inset.h | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 1f0c62b725..f38c78d3ea 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -1379,7 +1379,9 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y, // Try to descend recursively inside the inset. Inset * edited = inset->editXY(cur, x, y); - if (edited == inset && cur.pos() == it->pos) { + // FIXME: it is not clear that the test on position is needed + // Remove it if/when semantics of editXY is clarified + if (cur.text() == text_ && cur.pos() == it->pos) { // non-editable inset, set cursor after the inset if x is // nearer to that position (bug 9628) bool bound = false; // is modified by getPosNearX diff --git a/src/TextMetrics.h b/src/TextMetrics.h index 2f6181d0b0..e5aa061156 100644 --- a/src/TextMetrics.h +++ b/src/TextMetrics.h @@ -179,7 +179,9 @@ public: that is completely visible \param up whether we are going up or down (only used when assert_in_view is true - \retval inset is non-null if the cursor is positionned inside + \retval inset is null if the cursor is positioned over normal + text in the current Text object. Otherwise it is the inset + that the cursor points to, like for Inset::editXY. */ /// FIXME: cleanup to use BufferView::getCoveringInset() and /// setCursorFromCoordinates() instead of checkInsetHit(). diff --git a/src/insets/Inset.h b/src/insets/Inset.h index df94fe43b7..cbb8181dd3 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -185,7 +185,11 @@ public: /// cursor enters virtual void edit(Cursor & cur, bool front, EntryDirection entry_from = ENTRY_DIRECTION_IGNORE); - /// cursor enters + /// sets cursor recursively descending into nested editable insets + /** + \return the inset pointer if x,y is covering that inset + \param x,y are absolute screen coordinates. + */ /// Note: this method must preserve the selection status. See: /// https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg199001.html virtual Inset * editXY(Cursor & cur, int x, int y); -- 2.39.5