http://bugzilla.lyx.org/show_bug.cgi?id=4368

The second part of the attached patch (against branch) fixes this (pit can be 
invalid if a multi-par cell is replaced by content with lesser paragraphs, as 
in the reported case).

The first part sanitizes LFUN_FILE_INSERT_PLAINTEXT[_PARA], where the cursor 
might become invalid for the same reasons than in LFUN_CLIPBOARD_PASTE. 
Furthermore, I've added a missing undo recording.

I'm gonna commit to branch and trunk.

Jürgen
Index: src/insets/InsetTabular.cpp
===================================================================
--- src/insets/InsetTabular.cpp	(Revision 21913)
+++ src/insets/InsetTabular.cpp	(Arbeitskopie)
@@ -3376,8 +3376,18 @@
 	case LFUN_FILE_INSERT_PLAINTEXT_PARA:
 	case LFUN_FILE_INSERT_PLAINTEXT: {
 		// FIXME UNICODE
-		docstring const tmpstr = getContentsOfPlaintextFile(&cur.bv(), to_utf8(cmd.argument()), false);
-		if (!tmpstr.empty() && !insertPlaintextString(cur.bv(), tmpstr, false))
+		docstring const tmpstr =
+			getContentsOfPlaintextFile(&cur.bv(), to_utf8(cmd.argument()), false);
+		if (tmpstr.empty())
+			break;
+		recordUndoInset(cur, Undo::INSERT);
+		if (insertPlaintextString(cur.bv(), tmpstr, false)) {
+			// content has been replaced,
+			// so cursor might be invalid
+			cur.pos() = cur.lastpos();
+			cur.pit() = cur.lastpit();
+			bvcur.setCursor(cur);
+		} else
 			cur.undispatched();
 		break;
 	}
@@ -3428,6 +3438,7 @@
 				// content has been replaced,
 				// so cursor might be invalid
 				cur.pos() = cur.lastpos();
+				cur.pit() = cur.lastpit();
 				bvcur.setCursor(cur);
 				break;
 			}

Reply via email to