commit 498a5cd487482f1a97c2c9f305b9e10fc041631e
Author: Kornel Benko <[email protected]>
Date:   Thu Mar 10 10:51:02 2022 +0100

    FindAdv: Added possibility to search also in deactvated branches
    
    To include content of deactivated branches to the searched region
    one has to use the lyx-funcion
        search-ignore non-output-content true
---
 src/LyXAction.cpp          |    2 +-
 src/OutputParams.h         |    9 +++++----
 src/Paragraph.cpp          |    2 +-
 src/insets/InsetBranch.cpp |    4 ++--
 src/lyxfind.cpp            |   20 +++++++++++++++++++-
 src/output_latex.cpp       |    6 +++---
 6 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 704b37a..164327b 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -3508,7 +3508,7 @@ void LyXAction::init()
  * \var lyx::FuncCode lyx::LFUN_SEARCH_IGNORE
  * \li Action: Enables/disables searching for features in findadv
  * \li Syntax: search-ignore <type> <value>
- * \li Params: <type>: 
language|color|sectioning|font|series|shape|family|markup|underline|strike|deleted\n
+ * \li Params: <type>: 
language|color|sectioning|font|series|shape|family|markup|underline|strike|deleted|non-output-content\n
  * \li Params: <value>: true|false
  * \endvar
  */
diff --git a/src/OutputParams.h b/src/OutputParams.h
index a909ddd..d00ec02 100644
--- a/src/OutputParams.h
+++ b/src/OutputParams.h
@@ -426,12 +426,13 @@ public:
 
        /// Are we generating this material for use by advanced search?
        enum Search {
-               NoSearch,
-               SearchWithDeleted,
-               SearchWithoutDeleted
+               NoSearch = 0,
+               SearchWithDeleted = 1,
+               SearchWithoutDeleted = 2,
+               SearchNonOutput = 8
        };
                
-       enum Search for_searchAdv = NoSearch;
+       int for_searchAdv = NoSearch;
 
        /// Are we generating this material for instant preview?
        bool for_preview = false;
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index b9ac139..be133b1 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -2643,7 +2643,7 @@ void Paragraph::latex(BufferParams const & bparams,
                if (runparams.for_searchAdv == OutputParams::NoSearch)
                        output_changes = bparams.output_changes;
                else
-                       output_changes = (runparams.for_searchAdv == 
OutputParams::SearchWithDeleted);
+                       output_changes = ((runparams.for_searchAdv & 
OutputParams::SearchWithDeleted) != 0);
                if (c == META_INSET
                    && i >= start_pos && (end_pos == -1 || i < end_pos)) {
                        if (isDeleted(i))
diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp
index be8e551..2b60ca6 100644
--- a/src/insets/InsetBranch.cpp
+++ b/src/insets/InsetBranch.cpp
@@ -314,7 +314,7 @@ bool InsetBranch::producesOutput() const
 
 void InsetBranch::latex(otexstream & os, OutputParams const & runparams) const
 {
-       if (producesOutput()) {
+       if (producesOutput() || ((runparams.for_searchAdv & 
OutputParams::SearchNonOutput) != 0)) {
                OutputParams rp = runparams;
                rp.inbranch = true;
                InsetText::latex(os, rp);
@@ -328,7 +328,7 @@ void InsetBranch::latex(otexstream & os, OutputParams const 
& runparams) const
 int InsetBranch::plaintext(odocstringstream & os,
                           OutputParams const & runparams, size_t max_length) 
const
 {
-       if (!producesOutput())
+       if (!producesOutput() && ((runparams.for_searchAdv & 
OutputParams::SearchNonOutput) == 0))
                return 0;
 
        int len = InsetText::plaintext(os, runparams, max_length);
diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index a3ce988..54bceaa 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -106,6 +106,8 @@ class IgnoreFormats {
        ///
        void setIgnoreDeleted(bool value);
        ///
+       bool getNonContent() const { return searchNonContent_; }
+       ///
        void setIgnoreFormat(string const & type, bool value, bool fromUser = 
true);
 
 private:
@@ -132,6 +134,8 @@ private:
        bool userSelectedIgnoreLanguage_ = false;
        ///
        bool ignoreDeleted_ = true;
+       ///
+       bool searchNonContent_ = true;
 };
 
 void IgnoreFormats::setIgnoreFormat(string const & type, bool value, bool 
fromUser)
@@ -177,6 +181,9 @@ void IgnoreFormats::setIgnoreFormat(string const & type, 
bool value, bool fromUs
        else if (type == "deleted") {
                ignoreDeleted_ = value;
        }
+       else if (type == "non-output-content") {
+               searchNonContent_ = !value;
+       }
 }
 
 // The global variable that can be changed from outside
@@ -1059,6 +1066,9 @@ static docstring buffer_to_latex(Buffer & buffer)
                runparams.for_searchAdv = OutputParams::SearchWithoutDeleted;
        else
                runparams.for_searchAdv = OutputParams::SearchWithDeleted;
+       if (ignoreFormats.getNonContent()) {
+               runparams.for_searchAdv |= OutputParams::SearchNonOutput;
+       }
        pit_type const endpit = buffer.paragraphs().size();
        for (pit_type pit = 0; pit != endpit; ++pit) {
                TeXOnePar(buffer, buffer.text(), pit, os, runparams);
@@ -1088,6 +1098,9 @@ static docstring stringifySearchBuffer(Buffer & buffer, 
FindAndReplaceOptions co
                else {
                        runparams.for_searchAdv = 
OutputParams::SearchWithDeleted;
                }
+               if (ignoreFormats.getNonContent()) {
+                       runparams.for_searchAdv |= 
OutputParams::SearchNonOutput;
+               }
                for (pos_type pit = pos_type(0); pit < 
(pos_type)buffer.paragraphs().size(); ++pit) {
                        Paragraph const & par = buffer.paragraphs().at(pit);
                        LYXERR(Debug::FIND, "Adding to search string: '"
@@ -3829,6 +3842,9 @@ docstring stringifyFromCursor(DocIterator const & cur, 
int len)
                else {
                        runparams.for_searchAdv = 
OutputParams::SearchWithDeleted;
                }
+               if (ignoreFormats.getNonContent()) {
+                       runparams.for_searchAdv |= 
OutputParams::SearchNonOutput;
+               }
                LYXERR(Debug::FIND, "Stringifying with cur: "
                       << cur << ", from pos: " << cur.pos() << ", end: " << 
end);
                return par.asString(cur.pos(), end,
@@ -3853,7 +3869,6 @@ docstring stringifyFromCursor(DocIterator const & cur, 
int len)
        return docstring();
 }
 
-
 /** Computes the LaTeX export of buf starting from cur and ending len positions
  * after cur, if len is positive, or at the paragraph or innermost inset end
  * if len is -1.
@@ -3882,6 +3897,9 @@ docstring latexifyFromCursor(DocIterator const & cur, int 
len)
        else {
                runparams.for_searchAdv = OutputParams::SearchWithDeleted;
        }
+       if (ignoreFormats.getNonContent()) {
+               runparams.for_searchAdv |= OutputParams::SearchNonOutput;
+       }
 
        if (cur.inTexted()) {
                // @TODO what about searching beyond/across paragraph breaks ?
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index bf841fe..61537c8 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -465,7 +465,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
                if (runparams.for_searchAdv == OutputParams::NoSearch)
                        output_changes = buf.params().output_changes;
                else
-                       output_changes = (runparams.for_searchAdv == 
OutputParams::SearchWithDeleted);
+                       output_changes = ((runparams.for_searchAdv & 
OutputParams::SearchWithDeleted) != 0);
                if (size_t(pit + 1) < paragraphs.size()) {
                        ParagraphList::const_iterator nextpar = 
paragraphs.iterator_at(pit + 1);
                        Paragraph const & cpar = paragraphs.at(pit);
@@ -796,7 +796,7 @@ void TeXOnePar(Buffer const & buf,
 
        // Do not output empty commands if the whole paragraph has
        // been deleted with ct and changes are not output.
-       if ((runparams_in.for_searchAdv != OutputParams::SearchWithDeleted) && 
style.latextype != LATEX_ENVIRONMENT
+       if (((runparams_in.for_searchAdv & OutputParams::SearchWithDeleted) == 
0) && style.latextype != LATEX_ENVIRONMENT
            && !par.empty() && par.isDeleted(0, par.size()) && 
!bparams.output_changes)
                return;
 
@@ -1711,7 +1711,7 @@ void latexParagraphs(Buffer const & buf,
                if (runparams.for_searchAdv == OutputParams::NoSearch)
                        output_changes = bparams.output_changes;
                else
-                       output_changes = (runparams.for_searchAdv == 
OutputParams::SearchWithDeleted);
+                       output_changes = ((runparams.for_searchAdv & 
OutputParams::SearchWithDeleted) != 0);
                bool const lastpar = size_t(pit + 1) >= paragraphs.size();
                if (!lastpar) {
                        ParagraphList::const_iterator nextpar = 
paragraphs.iterator_at(pit + 1);
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to