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
This commit is contained in:
Kornel Benko 2022-03-10 10:51:02 +01:00
parent b257e2999b
commit 498a5cd487
6 changed files with 31 additions and 12 deletions

View File

@ -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
*/

View File

@ -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;

View File

@ -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))

View File

@ -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);

View File

@ -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 ?

View File

@ -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);