Hi,

this patch fixes all CT-related places in CutAndPaste.C.

Michael
Index: CutAndPaste.C
===================================================================
--- CutAndPaste.C	(Revision 14068)
+++ CutAndPaste.C	(Arbeitskopie)
@@ -6,6 +6,7 @@
  * \author Jürgen Vigna
  * \author Lars Gullik Bjønnes
  * \author Alfredo Braunstein
+ * \author Michael Gerz
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -78,7 +79,7 @@
 public:
 	resetParagraph(Buffer const & b) : buffer_(b) {}
 	void operator()(Paragraph & p) const {
-		p.cleanChanges();
+		p.setChange(Change(Change::UNCHANGED));
 		// ERT paragraphs have the Language latex_language.
 		// This is invalid outside of ERT, so we need to change it
 		// to the buffer language.
@@ -140,7 +141,8 @@
 		for (ParagraphList::size_type i = 0; i < insertion.size(); ++i) {
 			for (pos_type j = 0; j < insertion[i].size(); ++j) {
 				if (insertion[i].isNewline(j)) {
-					insertion[i].erase(j);
+					// do not track deletion of newline
+					insertion[i].erase(j, false);
 					breakParagraphConservative(
 							buffer.params(),
 							insertion, i, j);
@@ -185,17 +187,16 @@
 
 		// Set the inset owner of this paragraph.
 		tmpbuf->setInsetOwner(pars[pit].inInset());
+
 		for (pos_type i = 0; i < tmpbuf->size(); ++i) {
 			if (tmpbuf->getChar(i) == Paragraph::META_INSET &&
 			    !pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode()))
-				tmpbuf->erase(i--);
+				// do not track deletion of invalid insets
+				tmpbuf->erase(i--, false);
 		}
 
-		// reset change tracking status
-		if (buffer.params().tracking_changes)
-			tmpbuf->cleanChanges(Paragraph::trackingOn);
-		else
-			tmpbuf->cleanChanges(Paragraph::trackingOff);
+		tmpbuf->setChange(Change(buffer.params().trackChanges ?
+					 Change::INSERTED : Change::UNCHANGED));
 	}
 
 	bool const empty = pars[pit].empty();
@@ -293,25 +294,23 @@
 	// Start and end is inside same paragraph
 	if (endpit == pit_type(pars.size()) ||
 	    startpit == endpit) {
-		endpos -= pars[startpit].erase(startpos, endpos);
+		endpos -= pars[startpit].erase(startpos, endpos, params.trackChanges);
 		return PitPosPair(endpit, endpos);
 	}
 
-	// A paragraph break has to be physically removed by merging, but
-	// only if either (1) change tracking is off, or (2) the para break
-	// is "blue"
 	for (pit_type pit = startpit; pit != endpit + 1;) {
-		bool const merge = !params.tracking_changes ||
-			pars[pit].lookupChange(pars[pit].size()).type ==
-			Change::INSERTED;
+		// A paragraph break has to be physically removed only if either
+		// change tracking is off or the paragraph break is marked as inserted
+		bool const removeParBreak = !params.trackChanges ||
+			pars[pit].lookupChange(pars[pit].size()).type == Change::INSERTED;
 		pos_type const left  = ( pit == startpit ? startpos : 0 );
 		pos_type const right = ( pit == endpit ? endpos :
 				pars[pit].size() + 1 );
 		// Logical erase only:
-		pars[pit].erase(left, right);
-		// Separate handling of para break:
-		if (merge && pit != endpit &&
-		   (pit + 1 != endpit || pars[pit].hasSameLayout(pars[pit + 1]))) {
+		pars[pit].erase(left, right, params.trackChanges);
+		// Separate handling of paragraph break
+		if (removeParBreak && pit != endpit &&
+		    (pit + 1 != endpit || pars[pit].hasSameLayout(pars[pit + 1]))) {
 			pos_type const thissize = pars[pit].size();
 			if (doclear)
 				pars[pit + 1].stripLeadingSpaces();
@@ -346,11 +345,13 @@
 
 	// Cut out the end of the last paragraph.
 	Paragraph & back = paragraphs.back();
-	back.erase(end, back.size());
+	// do not track deletion here; it is an internal action not visible to the user
+	back.erase(end, back.size(), false);
 
 	// Cut out the begin of the first paragraph
 	Paragraph & front = paragraphs.front();
-	front.erase(0, start);
+	// again, do not track deletion
+	front.erase(0, start, false);
 
 	theCuts.push(make_pair(paragraphs, tc));
 }
@@ -587,7 +588,7 @@
 		BufferParams const & bp = cur.buffer().params();
 		pars.back().layout(bp.getLyXTextClass().defaultLayout());
 		for_each(pars.begin(), pars.end(), resetParagraph(cur.buffer()));
-		pars.back().insert(0, grabSelection(cur), LyXFont());
+		pars.back().insert(0, grabSelection(cur), LyXFont(), Change(Change::UNCHANGED));
 		theCuts.push(make_pair(pars, bp.textclass));
 	}
 	// tell tabular that a recent copy happened
@@ -676,7 +677,7 @@
 	string::const_iterator cit = str.begin();
 	string::const_iterator end = str.end();
 	for (; cit != end; ++cit, ++pos)
-		par.insertChar(pos, (*cit), font, Change(Change::INSERTED));
+		par.insertChar(pos, (*cit), font, cur.buffer().params().trackChanges);
 
 	// Cut the selection
 	cutSelection(cur, true, false);

Reply via email to