commit ec843830585fdeb1be9e48881c87e0bf8b830a7f
Author: Koji Yokota <[email protected]>
Date:   Sun Jun 15 16:38:30 2025 +0900

    Add usability check of math insets in a math hull
---
 src/Cursor.cpp               |  6 ++++++
 src/insets/Inset.cpp         |  1 +
 src/insets/InsetCode.h       | 24 +++++++++++++-----------
 src/mathed/InsetMathHull.cpp | 16 ++++++++++++++++
 src/mathed/InsetMathHull.h   |  2 +-
 5 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index b15b7ed3f8..cbce61c5f6 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -44,6 +44,7 @@
 #include "mathed/InsetMath.h"
 #include "mathed/InsetMathBrace.h"
 #include "mathed/InsetMathEnsureMath.h"
+#include "mathed/InsetMathHull.h"
 #include "mathed/InsetMathScript.h"
 #include "mathed/MacroTable.h"
 #include "mathed/MathData.h"
@@ -1786,6 +1787,11 @@ bool Cursor::macroModeClose(bool cancel)
        if (in && in->interpretString(*this, s))
                return true;
        bool const user_macro = buffer()->getMacro(name, *this, false);
+
+       // check if the inset can be used in the current math hull
+       if (in != nullptr && in->asHullInset() &&
+               
!in->asHullInset()->insetAllowed(insetCode("math"+to_utf8(name))))
+               return false;
        MathAtom atom = user_macro ? MathAtom(new InsetMathMacro(buffer(), 
name))
                                   : createInsetMath(name, buffer());
 
diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp
index 8884906b8e..3e9de261da 100644
--- a/src/insets/Inset.cpp
+++ b/src/insets/Inset.cpp
@@ -161,6 +161,7 @@ static void build_translator()
        insetnames[MATH_REF_CODE] = InsetName("mathref");
        insetnames[MATH_ROOT_CODE] = InsetName("mathroot");
        insetnames[MATH_SCRIPT_CODE] = InsetName("mathscript");
+       insetnames[MATH_SHORTINTERTEXT_CODE] = InsetName("mathshortintertext");
        insetnames[MATH_SIZE_CODE] = InsetName("mathsize");
        insetnames[MATH_SPACE_CODE] = InsetName("mathspace", _("Horizontal Math 
Space"));
        insetnames[MATH_SPECIALCHAR_CODE] = InsetName("mathspecialchar");
diff --git a/src/insets/InsetCode.h b/src/insets/InsetCode.h
index e7d113ef1a..a375500f60 100644
--- a/src/insets/InsetCode.h
+++ b/src/insets/InsetCode.h
@@ -193,13 +193,15 @@ enum InsetCode {
        ///
        MATH_SCRIPT_CODE,
        ///
+       MATH_SHORTINTERTEXT_CODE,
+       ///
        MATH_SIZE_CODE,
        ///
        MATH_SPACE_CODE,
        ///
-       MATH_SPECIALCHAR_CODE,
+       MATH_SPECIALCHAR_CODE, // 90
        ///
-       MATH_SPLIT_CODE, // 90
+       MATH_SPLIT_CODE,
        ///
        MATH_SQRT_CODE,
        ///
@@ -207,9 +209,9 @@ enum InsetCode {
        ///
        MATH_STRING_CODE,
        ///
-       MATH_SUBSTACK_CODE,
+       MATH_SUBSTACK_CODE, // 95
        ///
-       MATH_SYMBOL_CODE, // 95
+       MATH_SYMBOL_CODE,
        ///
        MATH_TABULAR_CODE,
        ///
@@ -217,9 +219,9 @@ enum InsetCode {
        ///
        MATH_UNDERSET_CODE,
        ///
-       MATH_UNKNOWN_CODE,
+       MATH_UNKNOWN_CODE, // 100
        ///
-       MATH_XARROW_CODE, // 100
+       MATH_XARROW_CODE,
        ///
        MATH_XYMATRIX_CODE,
        ///
@@ -227,9 +229,9 @@ enum InsetCode {
        ///
        ARGUMENT_PROXY_CODE,
        ///
-       PREVIEW_CODE,
+       PREVIEW_CODE, // 105
        ///
-       MATH_DIAGRAM_CODE, // 105
+       MATH_DIAGRAM_CODE,
        ///
        SCRIPT_CODE,
        ///
@@ -237,9 +239,9 @@ enum InsetCode {
        ///
        IPACHAR_CODE,
        ///
-       IPADECO_CODE,
+       IPADECO_CODE, // 110
        ///
-       MATH_CLASS_CODE, // 110
+       MATH_CLASS_CODE,
        ///
        COUNTER_CODE,
        ///
@@ -247,7 +249,7 @@ enum InsetCode {
        ///
        INDEXMACRO_SORTKEY_CODE,
        ///
-       INSET_CODE_SIZE
+       INSET_CODE_SIZE // 115
 };
 
 } // namespace lyx
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index e35bd22c61..0746d897c0 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -908,6 +908,22 @@ bool InsetMathHull::notifyCursorLeaves(Cursor const & old, 
Cursor & cur)
 }
 
 
+bool InsetMathHull::insetAllowed(InsetCode code) const
+{
+       switch (code) {
+       case MATH_INTERTEXT_CODE:
+       case MATH_SHORTINTERTEXT_CODE:
+               for (HullType const & env : mathedConflictEnvs()) {
+                       if (getType() == env)
+                               return false;
+               }
+               return true;
+       default:
+               return !isPassThru();
+       }
+}
+
+
 docstring InsetMathHull::label(row_type row) const
 {
        LASSERT(row < nrows(), return docstring());
diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h
index 8d79861d53..88b20fdbae 100644
--- a/src/mathed/InsetMathHull.h
+++ b/src/mathed/InsetMathHull.h
@@ -160,7 +160,7 @@ public:
        /// get notification when the cursor leaves this inset
        bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
        ///
-       //bool insetAllowed(InsetCode code) const override;
+       bool insetAllowed(InsetCode code) const override;
        ///
        void addPreview(DocIterator const & inset_pos,
                graphics::PreviewLoader &) const override;
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to