From 6d425078a796531d3abb6a9a858fecdfa85af6be Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Sat, 12 Mar 2011 01:40:01 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37903 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/OutputParams.cpp | 2 +- src/OutputParams.h | 6 ++++++ src/Paragraph.cpp | 2 ++ src/insets/InsetBox.cpp | 5 ++++- src/insets/InsetFloat.cpp | 2 ++ src/insets/InsetFoot.cpp | 8 ++++++-- src/insets/InsetTabular.cpp | 4 ++++ src/insets/InsetText.cpp | 3 +++ src/mathed/InsetMathNest.cpp | 9 ++++++++- 9 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/OutputParams.cpp b/src/OutputParams.cpp index 3ef6c7ace8..dc3d396426 100644 --- a/src/OutputParams.cpp +++ b/src/OutputParams.cpp @@ -27,7 +27,7 @@ OutputParams::OutputParams(Encoding const * enc) 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) diff --git a/src/OutputParams.h b/src/OutputParams.h index c9129eae3e..50009ebbbc 100644 --- a/src/OutputParams.h +++ b/src/OutputParams.h @@ -218,6 +218,12 @@ public: */ 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; diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 9f3fb5ec98..d5f4a5869c 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -1117,6 +1117,8 @@ void Paragraph::Private::latexInset(BufferParams const & bparams, 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. diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index 9999426444..1273ac9e08 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -271,7 +271,10 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const } } - 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"; diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index e3876ba1c3..a1bddb0a22 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -374,6 +374,8 @@ void InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const // Force \begin{} 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) diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp index d7eee84175..489358a110 100644 --- a/src/insets/InsetFoot.cpp +++ b/src/insets/InsetFoot.cpp @@ -90,12 +90,16 @@ void InsetFoot::latex(otexstream & os, OutputParams const & runparams_in) const // 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}"; diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 8c9824161e..948cad58d6 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -2563,6 +2563,10 @@ void Tabular::latex(otexstream & os, OutputParams const & runparams) const //+ first the opening preamble + //+--------------------------------------------------------------------- + os << safebreakln; + if (runparams.lastid != -1) + os.texrow().start(runparams.lastid, runparams.lastpos); + if (rotate) os << "\\begin{sideways}\n"; diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index e9105080a6..f0a6c81832 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -391,6 +391,9 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const 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()); diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index edbe99aea0..438039196f 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -402,7 +402,14 @@ void InsetMathNest::latex(otexstream & os, OutputParams const & runparams) const 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); } -- 2.39.5