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

The problem is simply that stripLeadingSpaces is called on the last
paragraph of the selection and the endpos position is not adjusted if the
par shrinks.

Can someone remind me why do we need to call stripLeadingSpaces? Is this
something related to change tracking?

 CutAndPaste.cpp |   17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

A/


Index: src/CutAndPaste.cpp
===================================================================
--- src/CutAndPaste.cpp	(revision 18938)
+++ src/CutAndPaste.cpp	(working copy)
@@ -302,12 +302,6 @@
 	for (pit_type pit = startpit; pit != endpit + 1;) {
 		pos_type const left  = (pit == startpit ? startpos : 0);
 		pos_type right = (pit == endpit ? endpos : pars[pit].size() + 1);
-		// FIXME: this is a quick fix for bug 3600. It stops a crash but the problem
-		// still remains unsolved (e.g. the second example in the bug report).
-		// c.f. http://bugzilla.lyx.org/show_bug.cgi?id=3600
-		if (right > pars[pit].size() + 1)
-			right = pars[pit].size() + 1;
-
 		bool const merge = pars[pit].isMergedOnEndOfParDeletion(params.trackChanges);
 
 		// Logically erase only, including the end-of-paragraph character
@@ -315,14 +309,17 @@
 
 		// Separate handling of paragraph break:
 		if (merge && pit != endpit &&
-		    (pit + 1 != endpit || pars[pit].hasSameLayout(pars[pit + 1]))) {
-			pos_type const thissize = pars[pit].size();
+		    (pit + 1 != endpit || pars[pit].hasSameLayout(pars[endpit]))) {
+			int const nextsize = pars[pit + 1].size();
 			if (doclear)
 				pars[pit + 1].stripLeadingSpaces(params.trackChanges);
+			if (pit == endpit) {
+				endpos += pars[pit].size();
+				endpos -= nextsize - pars[endpit].size();
+				endpos = std::max(endpos, 0);
+			}
 			mergeParagraph(params, pars, pit);
 			--endpit;
-			if (pit == endpit)
-				endpos += thissize;
 		} else
 			++pit;
 	}

Reply via email to