commit 6e7ed608866ae6cdad83476a69eda9fed585a0bf
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Wed Oct 22 14:32:43 2025 +0200
Fixup a25d94c3: Fix context menu with nested insets
g(Pit|Row)NearY now return -1 or nullptr when strict=true and the y
coordinate is outside of the block of text.
This avoids a situation when the context menu of a collapsible maenu
could be replaced by the context menu of the first nested inset.
Fixes ticket #13236.
(cherry picked from commit ecdb0e17aeb274f05d0871b20c322cc0e168f13e)
---
src/TextMetrics.cpp | 26 ++++++++++++++------------
src/TextMetrics.h | 10 ++++++++--
2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index d358b128a6..4339c74765 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1465,7 +1465,7 @@ pair<pos_type, bool> TextMetrics::getPosNearX(Row const &
row, int & x) const
// y is screen coordinate
-pit_type TextMetrics::getPitNearY(int y)
+pit_type TextMetrics::getPitNearY(int y, bool strict)
{
LASSERT(!text_->paragraphs().empty(), return -1);
LASSERT(!par_metrics_.empty(), return -1);
@@ -1479,11 +1479,11 @@ pit_type TextMetrics::getPitNearY(int y)
if (y < it->second.top()) {
// We are looking for a position that is before the first
paragraph in
- // the cache (which is in priciple off-screen, that is before
the
- // visible part.
+ // the cache (which is in principle off-screen, that is before
the
+ // visible part).
if (it->first == 0)
// We are already at the first paragraph in the inset.
- return 0;
+ return strict ? -1 : 0;
// OK, this is the paragraph we are looking for.
pit = it->first - 1;
newParMetricsUp();
@@ -1492,12 +1492,12 @@ pit_type TextMetrics::getPitNearY(int y)
if (y >= par_metrics_[last->first].bottom()) {
// We are looking for a position that is after the last
paragraph in
- // the cache (which is in priciple off-screen), that is before
the
- // visible part.
+ // the cache (which is in principle off-screen, that is after
the
+ // visible part).
pit = last->first + 1;
if (pit == int(text_->paragraphs().size()))
// We are already at the last paragraph in the inset.
- return last->first;
+ return strict ? -1 : last->first;
// OK, this is the paragraph we are looking for.
newParMetricsDown();
return pit;
@@ -1512,10 +1512,11 @@ pit_type TextMetrics::getPitNearY(int y)
}
-Row const * TextMetrics::getRowNearY(int & y)
+Row const * TextMetrics::getRowNearY(int y, bool strict)
{
- pit_type const pit = getPitNearY(y);
- LASSERT(pit != -1, return nullptr);
+ pit_type const pit = getPitNearY(y, strict);
+ if (pit == -1)
+ return nullptr;
ParagraphMetrics const & pm = par_metrics_[pit];
int yy = pm.top();
@@ -1617,8 +1618,9 @@ Row::Element const * TextMetrics::checkInsetHit(Row const
& row, int x) const
//takes screen x,y coordinates
Inset * TextMetrics::checkInsetHit(int x, int y)
{
- Row const * row = getRowNearY(y);
- LASSERT(row != nullptr, return nullptr);
+ Row const * row = getRowNearY(y, true);
+ if (row == nullptr)
+ return nullptr;
Row::Element const * e = checkInsetHit(*row, x);
return e ? const_cast<Inset *>(e->inset) : nullptr;
diff --git a/src/TextMetrics.h b/src/TextMetrics.h
index ea400ca5a7..106d4cb04f 100644
--- a/src/TextMetrics.h
+++ b/src/TextMetrics.h
@@ -203,12 +203,18 @@ private:
/// paragraph. The y-coordinate is allowed to be off-screen and
/// the metrics will be automatically updated if needed. This is
/// the reason why we need a non const BufferView.
+ /// \param y the vertical position of interest (relative to the screen).
+ /// \param strict : when true, return -1 when \c y points either
+ /// above or below the text contents.
/// FIXME: check whether this is still needed
- pit_type getPitNearY(int y);
+ pit_type getPitNearY(int y, bool strict = false);
/// returns the row near the specified y-coordinate in a given paragraph
/// (relative to the screen).
- Row const * getRowNearY(int & y);
+ /// \param y the vertical position of interest (relative to the screen).
+ /// \param strict : when true, return nullptr when \c y points either
+ /// above or below the text contents.
+ Row const * getRowNearY(int y, bool strict = false);
public:
/// returns the position near the specified x-coordinate of the row.
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs