commit 9296344b9a26191a2092d175a51e357ecc35145d
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Tue Feb 20 12:09:10 2018 +0100

    Kill macro mode when using LFUN_ESCAPE
    
    Add a `cancel' boolean to macroModeClose() that just removes all trace
    of what has been entered instead of finalizing it.
    
    When entering a macro in mathed, let LFUN_ESCAPE invoke
    macroModeClose(true). The new semantics of LFUN_ESCAPE in mathed is
    thus to abort the input of a macro name.
    
    Fixes bug #9251.
---
 src/Cursor.cpp               |    4 ++--
 src/Cursor.h                 |    6 +++---
 src/mathed/InsetMathNest.cpp |    8 ++++++--
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 2ad8bd4..173729b 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -1672,7 +1672,7 @@ void Cursor::setTargetX()
 }
 
 
-bool Cursor::macroModeClose()
+bool Cursor::macroModeClose(bool cancel)
 {
        if (!inMacroMode())
                return false;
@@ -1685,7 +1685,7 @@ bool Cursor::macroModeClose()
        cell().erase(pos());
 
        // do nothing if the macro name is empty
-       if (s == "\\")
+       if (s == "\\" || cancel)
                return false;
 
        // trigger updates of macros, at least, if no full
diff --git a/src/Cursor.h b/src/Cursor.h
index c028adf..5ca98cb 100644
--- a/src/Cursor.h
+++ b/src/Cursor.h
@@ -501,9 +501,9 @@ public:
        ///
        void plainInsert(MathAtom const & at);
 
-       /// interpret name of a macro. Returns true if something got
-       /// inserted.
-       bool macroModeClose();
+       /// interpret name of a macro or ditch it if \c cancel is true.
+       /// Returns true if something got inserted.
+       bool macroModeClose(bool cancel = false);
        /// are we currently typing the name of a macro?
        bool inMacroMode() const;
        /// get access to the macro we are currently typing
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 229b923..a03aaef 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -836,8 +836,12 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & 
cmd)
                if (cur.selection())
                        cur.clearSelection();
                else  {
-                       cmd = FuncRequest(LFUN_FINISHED_FORWARD);
-                       cur.undispatched();
+                       if (cur.inMacroMode())
+                               cur.macroModeClose(true);
+                       else {
+                               cmd = FuncRequest(LFUN_FINISHED_FORWARD);
+                               cur.undispatched();
+                       }
                }
                break;
 

Reply via email to