]> git.lyx.org Git - features.git/commitdiff
Do not allow nesting macro names in macro names
authorEnrico Forestieri <forenr@lyx.org>
Mon, 21 Nov 2022 17:24:29 +0000 (18:24 +0100)
committerEnrico Forestieri <forenr@lyx.org>
Mon, 21 Nov 2022 17:24:29 +0000 (18:24 +0100)
LyX removes a single backslash when it is inserted in a
macro name by the keyboard. However if it is followed by
another character before moving the cursor, it is retained
causing an assertion (bug #12601).

src/mathed/InsetMathNest.cpp

index 70ef1858c4cdec570446fc0ba842055e0a6e231f..673a62d5754a920f448e331aaea7e2b8e7bc97d9 100644 (file)
@@ -1825,9 +1825,15 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
                //lyxerr << "starting with macro" << endl;
                bool reduced = cap::reduceSelectionToOneCell(cur);
                if (reduced || !cur.selection()) {
+                       InsetMath const * im = cur.inset().asInsetMath();
+                       InsetMathMacro const * macro = im ? im->asMacro()
+                                                         : nullptr;
+                       bool in_macro_name = macro
+                               && macro->displayMode() ==
+                                       InsetMathMacro::DISPLAY_UNFOLDED;
                        cur.recordUndoInset();
                        docstring const safe = cap::grabAndEraseSelection(cur);
-                       if (!cur.inRegexped())
+                       if (!cur.inRegexped() && !in_macro_name)
                                cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), safe, false)));
                        else
                                cur.niceInsert(createInsetMath("backslash", buf));