>>>>> "Andre" == Andre Poenitz <[EMAIL PROTECTED]> writes:

Andre> prevAtom(). Or maybe nextAtom(). Should be near the cursor,
Andre> shouldn't it?

OK, here is my next try. I kind of like the code now, so I'd really
want to commit it and be done with this bug?

Can somebody test? It fixes a crash introduced by my first fix to 2034
(the change at the end of macroModeClose). If it is decided that 2034
should wait, this part should be applied anyway.

JMarc

Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.2353
diff -u -p -r1.2353 ChangeLog
--- src/ChangeLog	9 Jan 2006 21:00:22 -0000	1.2353
+++ src/ChangeLog	10 Jan 2006 12:15:42 -0000
@@ -1,3 +1,8 @@
+2006-01-10  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* cursor.C (macroModeClose): returns true if an inset actually got
+	inserted; revert faulty fix to bug 2034.
+
 2006-01-07  Georg Baum  <[EMAIL PROTECTED]>
 
 	* outputparams.[Ch]: add new flag inComment
Index: src/cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.140
diff -u -p -r1.140 cursor.C
--- src/cursor.C	20 Dec 2005 16:24:17 -0000	1.140
+++ src/cursor.C	10 Jan 2006 12:15:42 -0000
@@ -825,10 +825,10 @@ bool LCursor::down()
 }
 
 
-void LCursor::macroModeClose()
+bool LCursor::macroModeClose()
 {
 	if (!inMacroMode())
-		return;
+		return false;
 	MathUnknownInset * p = activeMacro();
 	p->finalize();
 	string const s = p->name();
@@ -837,7 +837,7 @@ void LCursor::macroModeClose()
 
 	// do nothing if the macro name is empty
 	if (s == "\\")
-		return;
+		return false;
 
 	// prevent entering of recursive macros
 	// FIXME: this is only a weak attempt... only prevents immediate
@@ -847,11 +847,8 @@ void LCursor::macroModeClose()
 	if (macro && macro->getInsetName() == name)
 		lyxerr << "can't enter recursive macro" << endl;
 
-	// Going back and forth between LCursor and mathed is a bit
-	// ridiculous, but the alternative was to duplicate the code
-	// in MathNestInset::doDispatch/LFUN_INSERT_MATH (which puts
-	// the cursor in the newly created inset). (JMarc 2005/12/20)
-	dispatch(FuncRequest(LFUN_INSERT_MATH, s));
+	plainInsert(createMathInset(name));
+	return true;
 }
 
 
Index: src/cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.h,v
retrieving revision 1.75
diff -u -p -r1.75 cursor.h
--- src/cursor.h	15 Jul 2005 15:49:30 -0000	1.75
+++ src/cursor.h	10 Jan 2006 12:15:42 -0000
@@ -256,8 +256,10 @@ public:
 	/// in pixels from top of screen
 	void setScreenPos(int x, int y);
 	/// current offset in the top cell
-	/// interpret name a name of a macro
-	void macroModeClose();
+
+	/// interpret name a name of a macro. Returns true if
+	/// something got inserted.
+	bool macroModeClose();
 	/// are we currently typing the name of a macro?
 	bool inMacroMode() const;
 	/// get access to the macro we are currently typing
Index: src/mathed/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/ChangeLog,v
retrieving revision 1.539
diff -u -p -r1.539 ChangeLog
--- src/mathed/ChangeLog	1 Jan 2006 20:28:04 -0000	1.539
+++ src/mathed/ChangeLog	10 Jan 2006 12:15:42 -0000
@@ -1,4 +1,10 @@
-2006-01-01    <[EMAIL PROTECTED]>
+2006-01-10  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* math_nestinset.C (doDispatch/LFUN_SELFINSERT): when inserting a
+	space and macromode is on, try to put the cursor inside the newly
+	created inset (bug 2034).
+
+2006-01-01  Lars Gullik Bjønnes  <[EMAIL PROTECTED]>
 
 	* command_inset.C (editXY): unused parameters
 
Index: src/mathed/math_nestinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_nestinset.C,v
retrieving revision 1.179
diff -u -p -r1.179 math_nestinset.C
--- src/mathed/math_nestinset.C	2 Dec 2005 06:34:19 -0000	1.179
+++ src/mathed/math_nestinset.C	10 Jan 2006 12:15:42 -0000
@@ -669,7 +669,19 @@ void MathNestInset::doDispatch(LCursor &
 		// undoes the complete macro, not only the last character.
 		if (!cur.inMacroMode())
 			recordUndo(cur);
-		if (!interpret(cur, cmd.argument[0])) {
+
+		// spacial handling of space. If we insert an inset
+		// via macro mode, we want to put the cursor inside it
+		// if relevant. Think typing "\frac<space>".
+		if (cmd.argument[0] == ' ' 
+		    && cur.inMacroMode() && cur.macroName() != "\\"
+		    && cur.macroModeClose()) {
+			MathAtom const atom = cur.prevAtom();
+			if (atom->asNestInset() && atom->nargs() > 0) {
+				cur.posLeft();
+				cur.pushLeft(*cur.nextInset());
+			}
+		} else if (!interpret(cur, cmd.argument[0])) {
 			cmd = FuncRequest(LFUN_FINISHED_RIGHT);
 			cur.undispatched();
 		}

Reply via email to