[LyX/2.5.x] Fix crash related to Cursor::macroModeClose().

Jean-Marc Lasgouttes <[email protected]>
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit 7c7a837e456ef05ab44549afaff94852e378d5a4
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Wed Mar 25 12:33:28 2026 +0100

    Fix crash related to Cursor::macroModeClose().
    
    Recipe sent to lyx-devel mailing list: open a new document, press
    Ctrl+M for creating a math box, write '\alpha' into the box, press
    right arrow key.
    
    What happens here is that, in handling of LFUN_CHAR_FORWARD in
    InsetMathNest::doDispatch, Cursor::macroModeClose is invoked (which
    turns \alpha to α) and then the cursor is moved forward. This, in turn,
    will lead to having the lfun undispatched and turned to
    LFUN_FINISHED_FORWARD. The consequence is that the flag Update::Force
    set by macroModeClose is overridden in Cursor::dispatch.
    
    The solution used here is to avoid moving the cursor if macroModeClose
    did something. This is a better behavior anyway. In existing code, if
    one is in a formula before a character and types "\alpha<right>" the
    cursor will jump after the character which is after the alpha. This is
    not nice.
    
    Add a note in Cursor::dispatch that resetting update flags may not be a
    good idea.
    
    The fact that this bug is new to 2.5.x is related to less systematic
    full screen updates in LyX 2.5.x.
    
    (cherry picked from commit edffc7d6ed372fd3ee2337169470aafb5b18f578)
---
 src/Cursor.cpp               | 2 ++
 src/mathed/InsetMathNest.cpp | 8 ++++----
 status.25x                   | 3 +++
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index b5daf9c860..cc06268483 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -846,6 +846,8 @@ void Cursor::dispatch(FuncRequest const & cmd0)
 			safe.pos() = safe.lastpos();
 		}
 		operator=(safe);
+		// FIXME: should the screen update flags be preserved? After
+		// all an update may have been requested for a reason.
 		disp_.screenUpdate(Update::None);
 		disp_.dispatched(false);
 	} else {
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index cb025a0ce5..b628cb2ac9 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -976,10 +976,10 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
 		// Now that we know exactly what we want to do, let's do it!
 		cur.selHandle(select);
 		cur.clearTargetX();
-		cur.macroModeClose();
-		// try moving forward or backwards as necessary...
-		if (!(forward ? cur.mathForward(word) : cur.mathBackward(word))) {
-			// ... and if movement failed, then finish forward or backwards
+		// Try in order (1) close macromode and (2) move cursor...
+		if (!cur.macroModeClose()
+		     && !(forward ? cur.mathForward(word) : cur.mathBackward(word))) {
+			// ... and both failed, then finish forward or backward
 			// as necessary
 			cmd = FuncRequest(finish_lfun);
 			cur.undispatched();
diff --git a/status.25x b/status.25x
index e0840824a3..c014a23919 100644
--- a/status.25x
+++ b/status.25x
@@ -66,6 +66,9 @@ What's new
 
 * USER INTERFACE
 
+- Fix crash in mathed when using cursor right to end the input of
+  macro names like \alpha.
+
 - Fix cross-references dialog in mathed (bug 13285).
 
 - Fix pasting of partial math grids (bug 13277).
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.