]> git.lyx.org Git - features.git/commitdiff
Change cursor shape for clickable math insets
authorEnrico Forestieri <forenr@lyx.org>
Thu, 1 Apr 2021 14:59:55 +0000 (16:59 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Thu, 1 Apr 2021 14:59:55 +0000 (16:59 +0200)
Currently, only InsetMathRef and InsetMathSpace are clickable.

src/BufferView.cpp
src/BufferView.h

index 308cf7f5ba14cf6988dae206b55ff86dc4bd2bc7..ed5a09f0aaf65963e8c29906908e073488ed1318 100644 (file)
@@ -2383,12 +2383,50 @@ Inset const * BufferView::getCoveringInset(Text const & text,
 }
 
 
+Inset const * BufferView::clickableMathInset(InsetMathNest const * inset,
+               CoordCache::Insets const & inset_cache, int x, int y) const
+{
+       for (size_t i = 0; i < inset->nargs(); ++i) {
+               MathData const & ar = inset->cell(i);
+               for (size_t j = 0; j < ar.size(); ++j) {
+                       string const name = lyxerr.debugging(Debug::MATHED)
+                               ? insetName(ar[j].nucleus()->lyxCode())
+                               : string();
+                       LYXERR(Debug::MATHED, "Checking inset: " << name);
+                       if (ar[j].nucleus()->clickable(*this, x, y)) {
+                               if (inset_cache.covers(ar[j].nucleus(), x, y)) {
+                                       LYXERR(Debug::MATHED, "Clickable inset: "
+                                              << name);
+                                       return ar[j].nucleus();
+                               }
+                       }
+                       InsetMathNest const * imn =
+                               ar[j].nucleus()->asNestInset();
+                       if (imn) {
+                               Inset const * inner =
+                                       clickableMathInset(imn, inset_cache, x, y);
+                               if (inner)
+                                       return inner;
+                       }
+               }
+       }
+       return nullptr;
+}
+
+
 void BufferView::updateHoveredInset() const
 {
        // Get inset under mouse, if there is one.
        int const x = d->mouse_position_cache_.x_;
        int const y = d->mouse_position_cache_.y_;
        Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
+       if (covering_inset && covering_inset->asInsetMath()) {
+               Inset const * inner_inset = clickableMathInset(
+                               covering_inset->asInsetMath()->asNestInset(),
+                               coordCache().getInsets(), x, y);
+               if (inner_inset)
+                       covering_inset = inner_inset;
+       }
 
        d->clickable_inset_ = covering_inset && covering_inset->clickable(*this, x, y);
 
index ab5ba600289d11e65433fdaa4dc1bf83e8822321..88ad63646156cffc8aee14f3a8bec651025ceb45 100644 (file)
@@ -164,6 +164,9 @@ public:
        /// \return the math inset with a context menu for the given position
        Inset const * mathContextMenu(InsetMathNest const * inset,
                CoordCache::Insets const & inset_cache, int x, int y) const;
+       /// \return the clickable math inset for the given position
+       Inset const * clickableMathInset(InsetMathNest const * inset,
+               CoordCache::Insets const & inset_cache, int x, int y) const;
 
        /// Save the current position as bookmark.
        /// if idx == 0, save to temp_bookmark