commit ae4f767d1c156007513e4f1432a006bda37d0f8c
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Mon May 19 15:44:21 2025 +0200

    Fix crashe related to simple search and metrics update
    
    These crashes are a consequence of commit 7f85024f, which improved
    performance by not caching position of insets not visible on screen.
    This makes a difference, for example, in the case of a tabular inset
    which has only its top visible, not its cells.
    
    To this end, introduce the helper methods Inset::hasDim() and
    Inset::hasGeometry(), which rely on CoordCache.
    
    The later is used in InsetTabular: the methods hitSelectRow and
    hitSelectColumn return false early if no geometry information exists
    for the inset.
---
 src/insets/Inset.cpp        | 24 ++++++++++++++++++------
 src/insets/Inset.h          |  4 ++++
 src/insets/InsetTabular.cpp |  4 ++++
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp
index 70cef59c47..d60e4a8078 100644
--- a/src/insets/Inset.cpp
+++ b/src/insets/Inset.cpp
@@ -323,12 +323,6 @@ string Inset::contextMenuName() const
 }
 
 
-Dimension const Inset::dimension(BufferView const & bv) const
-{
-       return bv.coordCache().insets().dim(this);
-}
-
-
 InsetCode insetCode(string const & name)
 {
        build_translator();
@@ -613,6 +607,24 @@ bool Inset::editing(BufferView const * bv) const
 }
 
 
+bool Inset::hasDim(BufferView const & bv) const
+{
+       return bv.coordCache().insets().hasDim(this);
+}
+
+
+bool Inset::hasGeometry(BufferView const & bv) const
+{
+       return bv.coordCache().insets().has(this);
+}
+
+
+Dimension const Inset::dimension(BufferView const & bv) const
+{
+       return bv.coordCache().insets().dim(this);
+}
+
+
 int Inset::xo(BufferView const & bv) const
 {
        return bv.coordCache().insets().x(this);
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index d41c339ebb..13df0e1306 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -236,6 +236,10 @@ public:
        /// This can use \c drawMarkers() for example.
        virtual void drawDecoration(PainterInfo &, int, int) const {}
 
+       /// do we have dimension information for this inset ?
+       bool hasDim(BufferView const & bv) const;
+       /// do we have full geometry information for this inset ?
+       bool hasGeometry(BufferView const & bv) const;
        /// last metrics computed for the inset
        Dimension const dimension(BufferView const &) const;
        /// last drawn position for 'important' insets
diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index bbf25bb83e..76140cf508 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -5556,6 +5556,8 @@ void InsetTabular::addToToc(DocIterator const & cpit, 
bool output_active,
 
 bool InsetTabular::hitSelectRow(BufferView const & bv, int x) const
 {
+       if (!hasGeometry(bv))
+               return false;
        int const x0 = xo(bv) + ADD_TO_TABULAR_WIDTH;
        return x < x0 || x > x0 + tabular.width();
 }
@@ -5563,6 +5565,8 @@ bool InsetTabular::hitSelectRow(BufferView const & bv, 
int x) const
 
 bool InsetTabular::hitSelectColumn(BufferView const & bv, int y) const
 {
+       if (!hasGeometry(bv))
+               return false;
        int const y0 = yo(bv) - tabular.rowAscent(0) + 
tabular.offsetVAlignment();
        // FIXME: using ADD_TO_TABULAR_WIDTH is not really correct since
        // there is no margin added vertically to tabular insets.
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to