Jean-Marc Lasgouttes wrote:
> I like the patch a lot (removes ad-hoc code). Small nits:
>
>   +     if (&cur.inset() && cur.inset().forceDefaultParagraphs(cur.idx()))
> {
>
> You do not have to test for &cur.inset(), which is always true.

I would have bet I asserted without it, but obviously it doesn't.

>                   boost::tie(ppp, endpit) =
>   -                     pasteSelectionHelper(cur.buffer(),
>   +                     pasteSelectionHelper(cur,
>                                                 text->paragraphs(),
>   -                                             cur.pit(), cur.pos(),
>                                                 parlist, textclass,
>                                                 el);
>
> Can't you remove the second, third and fourth arguments of
> pasteSelectionHelper and get them from cur instead?

the second argument (text->paragraphs()) can be removed indeed, but I don't 
think parlist and textclass can be removed, because they are passed to 
pasteParagraphList as arguments (in case you refer to them; cur.pit() and 
cur.pos() have already been removed in the original patch).

> I'd like more testing but I won't have time. I attach the patch for
> reference.

Attached is an updated patch from me.

Jürgen
Index: src/insets/insetert.C
===================================================================
--- src/insets/insetert.C	(Revision 15010)
+++ src/insets/insetert.C	(Arbeitskopie)
@@ -255,7 +255,6 @@ void InsetERT::doDispatch(LCursor & cur,
 		ParagraphList::iterator const end = paragraphs().end();
 		for (ParagraphList::iterator par = paragraphs().begin();
 		     par != end; ++par) {
-			par->layout(layout);
 			// in case par had a manual label
 			par->setBeginOfBody();
 			pos_type const siz = par->size();
Index: src/insets/insetcharstyle.C
===================================================================
--- src/insets/insetcharstyle.C	(Revision 15010)
+++ src/insets/insetcharstyle.C	(Arbeitskopie)
@@ -229,27 +229,16 @@ void InsetCharStyle::doDispatch(LCursor 
 {
 	setInlined();
 	switch (cmd.action) {
-		case LFUN_MOUSE_PRESS:
+	
+	case LFUN_MOUSE_PRESS:
 			if (cmd.button() == mouse_button::button3)
 				has_label_ = !has_label_;
 			else
 				InsetText::doDispatch(cur, cmd);
 			break;
-	case LFUN_PASTE:
-	case LFUN_PASTESELECTION: {
+	default:
 		InsetCollapsable::doDispatch(cur, cmd);
-		BufferParams const & bp = cur.buffer().params();
-		LyXLayout_ptr const layout =
-			bp.getLyXTextClass().defaultLayout();
-		ParagraphList::iterator const end = paragraphs().end();
-		for (ParagraphList::iterator par = paragraphs().begin(); 
-				par != end; ++par)
-			par->layout(layout);
 		break;
-		}
-		default:
-			InsetCollapsable::doDispatch(cur, cmd);
-			break;
 	}
 }
 
Index: src/CutAndPaste.C
===================================================================
--- src/CutAndPaste.C	(Revision 15010)
+++ src/CutAndPaste.C	(Arbeitskopie)
@@ -116,11 +116,14 @@ bool checkPastePossible(int index)
 
 
 pair<PitPosPair, pit_type>
-pasteSelectionHelper(Buffer const & buffer, 
-		     ParagraphList & pars, pit_type pit, int pos,
-		     ParagraphList const & parlist, textclass_type textclass, 
-		     ErrorList & errorlist)
+pasteSelectionHelper(LCursor & cur, ParagraphList const & parlist,
+		     textclass_type textclass, ErrorList & errorlist)
 {
+	Buffer const & buffer = cur.buffer();
+	pit_type pit = cur.pit();
+	pos_type pos = cur.pos();
+	ParagraphList & pars = cur.text()->paragraphs();
+
 	if (parlist.empty())
 		return make_pair(PitPosPair(pit, pos), pit);
 
@@ -149,6 +152,19 @@ pasteSelectionHelper(Buffer const & buff
 		}
 	}
 
+	// If we are in an inset which returns forceDefaultParagraphs,
+	// set the paragraphs to default
+	// FIXME: pars[pit].forceDefaultParagraphs() should be enough,
+	// but returns the wrong values for tabular cells!
+	if (cur.inset().forceDefaultParagraphs(cur.idx())) {
+		LyXLayout_ptr const layout = 
+			buffer.params().getLyXTextClass().defaultLayout();
+		ParagraphList::iterator const end = insertion.end();
+		for (ParagraphList::iterator par = insertion.begin(); 
+				par != end; ++par)
+			par->layout(layout);
+	}
+
 	// Make sure there is no class difference.
 	InsetText in;
 	// This works without copying any paragraph data because we have
@@ -603,7 +619,7 @@ std::string getSelection(Buffer const & 
 }
 
 
-void pasteParagraphList(LCursor & cur, ParagraphList const & parlist, 
+void pasteParagraphList(LCursor & cur, ParagraphList const & parlist,
                         textclass_type textclass)
 {
 	if (cur.inTexted()) {
@@ -617,11 +633,7 @@ void pasteParagraphList(LCursor & cur, P
 		ErrorList el;
 
 		boost::tie(ppp, endpit) =
-			pasteSelectionHelper(cur.buffer(),
-                                             text->paragraphs(),
-                                             cur.pit(), cur.pos(),
-                                             parlist, textclass,
-                                             el);
+			pasteSelectionHelper(cur, parlist, textclass, el);
 		bufferErrors(cur.buffer(), el);
 		updateCounters(cur.buffer());
 		cur.clearSelection();

Reply via email to