The attached was posted on bugzilla to fix the problem when people press
Enter before or after an inset (inside float) in the hope of getting a
caption in the right place. It is an incomplete fix but will work for
the most common use cases, including the one Uwe described.

BTW shouldn't we be moving to insetcaption? There these problems will
probably be much easier to address, and the code base becomes cleaner.

- Martin

Index: text.C
===================================================================
--- text.C      (revision 13790)
+++ text.C      (working copy)
@@ -1068,6 +1068,13 @@ void LyXText::breakParagraph(LCursor & c
        // we need to set this before we insert the paragraph.
        bool const isempty = cpar.allowEmpty() && cpar.empty();
 
+       // Prepare for placing caption based on inset position:
+       bool const captionbelow = cur.pos() > 0 
+               && cpar.isInset(0) && !cpar.getInset(0)->isChar();
+       bool const captionabove = cur.pos() < cur.lastpos() 
+               && cpar.isInset(cur.pos()) 
+               && !cpar.getInset(cur.pos())->isChar();
+
        ::breakParagraph(cur.buffer().params(), paragraphs(), cpit,
                         cur.pos(), preserve_layout);
 
@@ -1076,13 +1083,22 @@ void LyXText::breakParagraph(LCursor & c
        cpit = cur.pit();
        pit_type next_par = cpit + 1;
 
-       // well this is the caption hack since one caption is really enough
+       // The caption hack. One caption is enough, and we place it under the
+       // existing inset if breaking to the right of it, and above the inset
+       // if breaking to the left of it. If no inset exists yet, we open up a
+       // standard paragraph for inserting an inset, cf. paragraph_funcs.C. 
+       // (MV)
        if (sensitive) {
-               if (cur.pos() == 0)
-                       // set to standard-layout
+                       // set the non-caption stuff to standard-layout and
+                       // captions to caption layout
+               if (captionbelow) {
+                       pars_[next_par].applyLayout(pars_[cpit].layout());
                        pars_[cpit].applyLayout(tclass.defaultLayout());
-               else
-                       // set to standard-layout
+               } else if (captionabove) {
+                       pars_[cpit].applyLayout(pars_[next_par].layout());
+                       pars_[next_par].applyLayout(tclass.defaultLayout());
+               } else if (cur.pos() != 0)
+                       // Suppress double captions:
                        pars_[next_par].applyLayout(tclass.defaultLayout());
        }
 

Attachment: pgpCoLSEKEfjo.pgp
Description: PGP signature

Reply via email to