>>>>> "Juergen" == Juergen Spitzmueller <[EMAIL PROTECTED]> writes:

Juergen> Jean-Marc Lasgouttes wrote:
>> Please test.

Juergen> Seems to work. However, LyX crashed two times on me while
Juergen> testing this. I'm not sure it is related, and I couldn't
Juergen> reproduce it, unfortunately.

Juergen> Also I get the debug output: I don't have a cell 1

Juergen> When I hit C-i in the outermost math inset.

OK, try this new version instead. I undid the simplifications to the
code, since they were wrong %-] So now the code for
LFUN_NEXT_INSET_TOGGLE is basically moved as is to BufferView::Pimpl.

One thing I failed to do is to allow locking an outermost math inset. 

JMarc

Index: src/BufferView_pimpl.C
===================================================================
--- src/BufferView_pimpl.C	(revision 14591)
+++ src/BufferView_pimpl.C	(working copy)
@@ -1054,6 +1054,7 @@ FuncStatus BufferView::Pimpl::getStatus(
 	case LFUN_BIBDB_ADD:
 	case LFUN_BIBDB_DEL:
 	case LFUN_WORDS_COUNT:
+	case LFUN_NEXT_INSET_TOGGLE:
 		flag.enabled(true);
 		break;
 
@@ -1351,6 +1352,30 @@ bool BufferView::Pimpl::dispatch(FuncReq
 		buffer_->params().compressed = !buffer_->params().compressed;
 		break;
 
+	case LFUN_NEXT_INSET_TOGGLE: {
+		// this is the real function we want to invoke
+		FuncRequest tmpcmd = FuncRequest(LFUN_INSET_TOGGLE, cmd.origin);
+		// if there is an inset at cursor, see whether it
+		// wants to toggle.
+		InsetBase * inset = cur.nextInset();
+		if (inset && inset->isActive()) {
+			LCursor tmpcur = cur;
+			tmpcur.pushLeft(*inset);
+			inset->dispatch(tmpcur, tmpcmd);
+			if (tmpcur.result().dispatched()) {
+				cur.dispatched();
+			}
+		}
+		// if it did not work, try the underlying inset.
+		if (!cur.result().dispatched())
+			cur.dispatch(tmpcmd);
+
+		if (cur.result().dispatched()) 
+			cur.clearSelection();
+		
+		break;
+	}
+
 	default:
 		return false;
 	}
Index: src/ChangeLog
===================================================================
--- src/ChangeLog	(revision 14591)
+++ src/ChangeLog	(working copy)
@@ -1,5 +1,13 @@
 2006-08-09  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
+	* BufferView_pimpl.C (dispatch/LFUN_NEXT_INSET_TOGGLE): moved from
+	LyXText.
+
+	* text3.C (dispatch/LFUN_NEXT_INSET_TOGGLE): moved to
+	BufferView::Pimpl, since this should work in mathed too.
+
+2006-08-09  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
 	* CutAndPaste.C (copySelection): remove annoying debug
 	message.
 
Index: src/mathed/ChangeLog
===================================================================
--- src/mathed/ChangeLog	(revision 14591)
+++ src/mathed/ChangeLog	(working copy)
@@ -1,5 +1,10 @@
 2006-08-09  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
+	* math_nestinset.C (doDispatch/LFUN_INSET_TOGGLE): do not try to
+	do the work which belongs to LFUN_NEXT_INSET_TOGGLE (bug 2756).
+
+2006-08-09  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
 	* math_nestinset.C (script): 
 	* math_scriptinset.C (removeScript): remove annoying debug
 	messages. 
Index: src/mathed/math_nestinset.C
===================================================================
--- src/mathed/math_nestinset.C	(revision 14591)
+++ src/mathed/math_nestinset.C	(working copy)
@@ -649,15 +649,8 @@ void MathNestInset::doDispatch(LCursor &
 
 	case LFUN_INSET_TOGGLE:
 		recordUndo(cur);
-		//lockToggle();
-		if (cur.pos() != cur.lastpos()) {
-			// toggle previous inset ...
-			cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
-		} else if (cur.popLeft() && cur.pos() != cur.lastpos()) {
-			// ... or enclosing inset if we are in the last inset position
-			cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
-			++cur.pos();
-		}
+		lock(!lock());
+		cur.popRight();
 		break;
 
 	case LFUN_SELFINSERT:
Index: src/text3.C
===================================================================
--- src/text3.C	(revision 14591)
+++ src/text3.C	(working copy)
@@ -674,28 +674,6 @@ void LyXText::dispatch(LCursor & cur, Fu
 		cur.inset().showInsetDialog(bv);
 		break;
 
-	case LFUN_NEXT_INSET_TOGGLE: {
-		InsetBase * inset = cur.nextInset();
-		// this is the real function we want to invoke
-		cmd = FuncRequest(LFUN_INSET_TOGGLE);
-		cur.undispatched();
-		// if there is an inset at cursor, see whether it
-		// wants to toggle.
-		if (inset) {
-			LCursor tmpcur = cur;
-			tmpcur.pushLeft(*inset);
-			inset->dispatch(tmpcur, cmd);
-			if (tmpcur.result().dispatched()) {
-				cur.clearSelection();
-				cur.dispatched();
-			}
-		}
-		// if it did not work, try the underlying inset.
-		if (!cur.result().dispatched())
-			cur.inset().dispatch(cur, cmd);
-		break;
-	}
-
 	case LFUN_SPACE_INSERT:
 		if (cur.paragraph().layout()->free_spacing)
 			insertChar(cur, ' ');
@@ -1719,7 +1697,6 @@ bool LyXText::getStatus(LCursor & cur, F
 	case LFUN_BREAKPARAGRAPH_SKIP:
 	case LFUN_PARAGRAPH_SPACING:
 	case LFUN_INSET_INSERT:
-	case LFUN_NEXT_INSET_TOGGLE:
 	case LFUN_UPCASE_WORD:
 	case LFUN_LOWCASE_WORD:
 	case LFUN_CAPITALIZE_WORD:

Reply via email to