Author: forenr
Date: Sat Mar 12 02:40:01 2011
New Revision: 37903
URL: http://www.lyx.org/trac/changeset/37903

Log:
When an error occurs, don't highlight more than necessary.
Currently, if an inset outputs a newline, the new latex row is still
associated with a previous id/pos. Now, if a latex error occurs before
this newline, we would still highlight everything associated to that
id/pos, even if it is extraneous to the error.
This is avoided by associating the new latex row with the id/pos in
effect right before entering the inset. If an inset does not output
a newline, it is not excluded from the selection, consistent with the
fact that the text of the inset does appear in the error description.

Modified:
   lyx-devel/trunk/src/OutputParams.cpp
   lyx-devel/trunk/src/OutputParams.h
   lyx-devel/trunk/src/Paragraph.cpp
   lyx-devel/trunk/src/insets/InsetBox.cpp
   lyx-devel/trunk/src/insets/InsetFloat.cpp
   lyx-devel/trunk/src/insets/InsetFoot.cpp
   lyx-devel/trunk/src/insets/InsetTabular.cpp
   lyx-devel/trunk/src/insets/InsetText.cpp
   lyx-devel/trunk/src/mathed/InsetMathNest.cpp

Modified: lyx-devel/trunk/src/OutputParams.cpp
==============================================================================
--- lyx-devel/trunk/src/OutputParams.cpp        Fri Mar 11 18:18:37 2011        
(r37902)
+++ lyx-devel/trunk/src/OutputParams.cpp        Sat Mar 12 02:40:01 2011        
(r37903)
@@ -27,7 +27,7 @@
          inComment(false), inTableCell(NO), inFloat(NONFLOAT),
          inIndexEntry(false), inDeletedInset(0),
          changeOfDeletedInset(Change::UNCHANGED),
-         par_begin(0), par_end(0), isLastPar(false),
+         par_begin(0), par_end(0), lastid(-1), lastpos(-1), isLastPar(false),
          dryrun(false), pass_thru(false), 
          html_disable_captions(false), html_in_par(false),
          html_make_pars(true), for_toc(false), includeall(false)

Modified: lyx-devel/trunk/src/OutputParams.h
==============================================================================
--- lyx-devel/trunk/src/OutputParams.h  Fri Mar 11 18:18:37 2011        (r37902)
+++ lyx-devel/trunk/src/OutputParams.h  Sat Mar 12 02:40:01 2011        (r37903)
@@ -218,6 +218,12 @@
         */
        mutable pit_type par_end;
 
+       /// Id of the last paragraph before an inset
+       mutable int lastid;
+
+       /// Last position in the last paragraph before an inset
+       mutable int lastpos;
+
        /// is this the last paragraph in the current buffer/inset?
        bool isLastPar;
        

Modified: lyx-devel/trunk/src/Paragraph.cpp
==============================================================================
--- lyx-devel/trunk/src/Paragraph.cpp   Fri Mar 11 18:18:37 2011        (r37902)
+++ lyx-devel/trunk/src/Paragraph.cpp   Sat Mar 12 02:40:01 2011        (r37903)
@@ -1117,6 +1117,8 @@
        int prev_rows = os.texrow().rows();
 
        try {
+               runparams.lastid = id_;
+               runparams.lastpos = i;
                inset->latex(os, runparams);
        } catch (EncodingException & e) {
                // add location information and throw again.

Modified: lyx-devel/trunk/src/insets/InsetBox.cpp
==============================================================================
--- lyx-devel/trunk/src/insets/InsetBox.cpp     Fri Mar 11 18:18:37 2011        
(r37902)
+++ lyx-devel/trunk/src/insets/InsetBox.cpp     Sat Mar 12 02:40:01 2011        
(r37903)
@@ -271,7 +271,10 @@
                }
        }
 
-       os << "%\n";
+       os << safebreakln;
+       if (runparams.lastid != -1)
+               os.texrow().start(runparams.lastid, runparams.lastpos);
+
        // Adapt to column/text width correctly also if paragraphs indented:
        if (stdwidth)
                os << "\\noindent";

Modified: lyx-devel/trunk/src/insets/InsetFloat.cpp
==============================================================================
--- lyx-devel/trunk/src/insets/InsetFloat.cpp   Fri Mar 11 18:18:37 2011        
(r37902)
+++ lyx-devel/trunk/src/insets/InsetFloat.cpp   Sat Mar 12 02:40:01 2011        
(r37903)
@@ -374,6 +374,8 @@
 
        // Force \begin{<floatname>} to appear in a new line.
        os << breakln << "\\begin{" << from_ascii(tmptype) << '}';
+       if (runparams.lastid != -1)
+               os.texrow().start(runparams.lastid, runparams.lastpos);
        // We only output placement if different from the def_placement.
        // sidewaysfloats always use their own page
        if (!placement.empty() && !params_.sideways)

Modified: lyx-devel/trunk/src/insets/InsetFoot.cpp
==============================================================================
--- lyx-devel/trunk/src/insets/InsetFoot.cpp    Fri Mar 11 18:18:37 2011        
(r37902)
+++ lyx-devel/trunk/src/insets/InsetFoot.cpp    Sat Mar 12 02:40:01 2011        
(r37903)
@@ -90,12 +90,16 @@
        // footnotes in titling commands like \title have moving arguments
        runparams.moving_arg |= runparams_in.intitle;
 
+       os << safebreakln;
+       if (runparams.lastid != -1)
+               os.texrow().start(runparams.lastid, runparams.lastpos);
+
        // in titling commands, \thanks should be used instead of \footnote.
        // some classes (e.g. memoir) do not understand \footnote.
        if (runparams_in.intitle)
-               os << "%\n\\thanks{";
+               os << "\\thanks{";
        else
-               os << "%\n\\footnote{";
+               os << "\\footnote{";
 
        InsetText::latex(os, runparams);
        os << "%\n}";

Modified: lyx-devel/trunk/src/insets/InsetTabular.cpp
==============================================================================
--- lyx-devel/trunk/src/insets/InsetTabular.cpp Fri Mar 11 18:18:37 2011        
(r37902)
+++ lyx-devel/trunk/src/insets/InsetTabular.cpp Sat Mar 12 02:40:01 2011        
(r37903)
@@ -2563,6 +2563,10 @@
        //+                      first the opening preamble                    +
        //+---------------------------------------------------------------------
 
+       os << safebreakln;
+       if (runparams.lastid != -1)
+               os.texrow().start(runparams.lastid, runparams.lastpos);
+
        if (rotate)
                os << "\\begin{sideways}\n";
 

Modified: lyx-devel/trunk/src/insets/InsetText.cpp
==============================================================================
--- lyx-devel/trunk/src/insets/InsetText.cpp    Fri Mar 11 18:18:37 2011        
(r37902)
+++ lyx-devel/trunk/src/insets/InsetText.cpp    Sat Mar 12 02:40:01 2011        
(r37903)
@@ -391,6 +391,9 @@
                            os << breakln;
                        else
                            os << safebreakln;
+                       if (runparams.lastid != -1)
+                               os.texrow().start(runparams.lastid,
+                                                 runparams.lastpos);
                        os << "\\begin{" << from_utf8(il.latexname()) << "}\n";
                        if (!il.latexparam().empty())
                                os << from_utf8(il.latexparam());

Modified: lyx-devel/trunk/src/mathed/InsetMathNest.cpp
==============================================================================
--- lyx-devel/trunk/src/mathed/InsetMathNest.cpp        Fri Mar 11 18:18:37 
2011        (r37902)
+++ lyx-devel/trunk/src/mathed/InsetMathNest.cpp        Sat Mar 12 02:40:01 
2011        (r37903)
@@ -402,7 +402,14 @@
        wi.canBreakLine(os.canBreakLine());
        write(wi);
        os.canBreakLine(wi.canBreakLine());
-       os.texrow().newlines(wi.line());
+
+       int lf = wi.line();
+       if (lf > 0 && runparams.lastid != -1) {
+               --lf;
+               os.texrow().newline();
+               os.texrow().start(runparams.lastid, runparams.lastpos);
+       }
+       os.texrow().newlines(lf);
 }
 
 

Reply via email to