mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-31 07:45:44 +00:00
FindAdv: Do not search in deleted text.
This commit is contained in:
parent
eab9108dc1
commit
469b43c791
@ -3622,10 +3622,10 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
|
|||||||
else { // match_len > 0
|
else { // match_len > 0
|
||||||
// Try to find the begin of searched string
|
// Try to find the begin of searched string
|
||||||
int increment;
|
int increment;
|
||||||
int firstInvalid = 100000;
|
int firstInvalid = cur.lastpos() - cur.pos();
|
||||||
{
|
{
|
||||||
int incrmatch = (mres.match_prefix + mres.pos - mres.leadsize + 1)*3/4;
|
int incrmatch = (mres.match_prefix + mres.pos - mres.leadsize + 1)*3/4;
|
||||||
int incrcur = (cur.lastpos() - cur.pos() + 1 )*3/4;
|
int incrcur = (firstInvalid + 1 )*3/4;
|
||||||
if (incrcur < incrmatch)
|
if (incrcur < incrmatch)
|
||||||
increment = incrcur;
|
increment = incrcur;
|
||||||
else
|
else
|
||||||
@ -3636,54 +3636,44 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
|
|||||||
LYXERR(Debug::FIND, "Set increment to " << increment);
|
LYXERR(Debug::FIND, "Set increment to " << increment);
|
||||||
while (increment > 0) {
|
while (increment > 0) {
|
||||||
DocIterator old_cur = cur;
|
DocIterator old_cur = cur;
|
||||||
size_t skipping = cur.depth();
|
if (cur.pos() + increment >= cur.lastpos()) {
|
||||||
for (int i = 0; i < increment && cur; i++) {
|
|
||||||
cur.forwardPos();
|
|
||||||
while (cur && cur.depth() > skipping) {
|
|
||||||
cur.pos() = cur.lastpos();
|
|
||||||
cur.forwardPos();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! cur || (cur.pit() > old_cur.pit())) {
|
|
||||||
// Are we outside of the paragraph?
|
|
||||||
// This can happen if moving past some UTF8-encoded chars
|
|
||||||
cur = old_cur;
|
|
||||||
increment /= 2;
|
increment /= 2;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else {
|
cur.pos() = cur.pos() + increment;
|
||||||
MatchResult mres2 = match(cur, -1, false);
|
MatchResult mres2 = match(cur, -1, false);
|
||||||
displayMres(mres2, "findForwardAdv loop", cur)
|
displayMres(mres2, "findForwardAdv loop", cur)
|
||||||
switch (interpretMatch(mres, mres2)) {
|
switch (interpretMatch(mres, mres2)) {
|
||||||
case MatchResult::newIsTooFar:
|
case MatchResult::newIsTooFar:
|
||||||
// behind the expected match
|
// behind the expected match
|
||||||
firstInvalid = increment;
|
firstInvalid = increment;
|
||||||
cur = old_cur;
|
cur = old_cur;
|
||||||
increment /= 2;
|
increment /= 2;
|
||||||
break;
|
break;
|
||||||
case MatchResult::newIsBetter:
|
case MatchResult::newIsBetter:
|
||||||
// not reached yet, but cur.pos()+increment is bettert
|
// not reached yet, but cur.pos()+increment is bettert
|
||||||
mres = mres2;
|
mres = mres2;
|
||||||
firstInvalid -= increment;
|
firstInvalid -= increment;
|
||||||
if (increment > firstInvalid*3/4)
|
if (increment > firstInvalid*3/4)
|
||||||
increment = firstInvalid*3/4;
|
increment = firstInvalid*3/4;
|
||||||
if ((mres2.pos == mres2.leadsize) && (increment >= mres2.match_prefix)) {
|
if ((mres2.pos == mres2.leadsize) && (increment >= mres2.match_prefix)) {
|
||||||
if (increment >= mres2.match_prefix)
|
if (increment >= mres2.match_prefix)
|
||||||
increment = (mres2.match_prefix+1)*3/4;
|
increment = (mres2.match_prefix+1)*3/4;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Todo@
|
// Todo@
|
||||||
// Handle not like MatchResult::newIsTooFar
|
// Handle not like MatchResult::newIsTooFar
|
||||||
LYXERR0( "Probably too far: Increment = " << increment << " match_prefix = " << mres.match_prefix);
|
LYXERR0( "Probably too far: Increment = " << increment << " match_prefix = " << mres.match_prefix);
|
||||||
firstInvalid--;
|
firstInvalid--;
|
||||||
increment = increment*3/4;
|
increment = increment*3/4;
|
||||||
cur = old_cur;
|
cur = old_cur;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mres.match_len > 0) {
|
if (mres.match_len > 0) {
|
||||||
if (mres.match_prefix + mres.pos - mres.leadsize > 0) {
|
if (mres.match_prefix + mres.pos - mres.leadsize > 0) {
|
||||||
|
// The match seems to indicate some deeper level
|
||||||
repeat = true;
|
repeat = true;
|
||||||
orig_cur = cur;
|
orig_cur = cur;
|
||||||
orig_mres = mres;
|
orig_mres = mres;
|
||||||
@ -3692,7 +3682,7 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (repeat) {
|
else if (repeat) {
|
||||||
// seems to never be reached.
|
// should never be reached.
|
||||||
cur = orig_cur;
|
cur = orig_cur;
|
||||||
mres = orig_mres;
|
mres = orig_mres;
|
||||||
}
|
}
|
||||||
@ -3700,15 +3690,15 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
|
|||||||
LYXERR(Debug::FIND, "Finalizing 1");
|
LYXERR(Debug::FIND, "Finalizing 1");
|
||||||
MatchResult found_match = findAdvFinalize(cur, match, mres);
|
MatchResult found_match = findAdvFinalize(cur, match, mres);
|
||||||
if (found_match.match_len > 0) {
|
if (found_match.match_len > 0) {
|
||||||
LASSERT(found_match.pos_len > 0, /**/);
|
LASSERT(found_match.pos_len > 0, /**/);
|
||||||
match.FillResults(found_match);
|
match.FillResults(found_match);
|
||||||
return found_match.pos_len;
|
return found_match.pos_len;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// try next possible match
|
// try next possible match
|
||||||
cur.forwardPos();
|
cur.forwardPos();
|
||||||
repeat = false;
|
repeat = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -444,7 +444,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
|
|||||||
if ((par->layout() != nextpar->layout()
|
if ((par->layout() != nextpar->layout()
|
||||||
|| par->params().depth() == nextpar->params().depth()
|
|| par->params().depth() == nextpar->params().depth()
|
||||||
|| par->params().leftIndent() == nextpar->params().leftIndent())
|
|| par->params().leftIndent() == nextpar->params().leftIndent())
|
||||||
&& !runparams.for_search && !cpar.empty()
|
&& !cpar.empty()
|
||||||
&& cpar.isDeleted(0, cpar.size()) && !buf.params().output_changes) {
|
&& cpar.isDeleted(0, cpar.size()) && !buf.params().output_changes) {
|
||||||
if (!buf.params().output_changes && !cpar.parEndChange().deleted())
|
if (!buf.params().output_changes && !cpar.parEndChange().deleted())
|
||||||
os << '\n' << '\n';
|
os << '\n' << '\n';
|
||||||
@ -759,7 +759,7 @@ void TeXOnePar(Buffer const & buf,
|
|||||||
|
|
||||||
// Do not output empty commands if the whole paragraph has
|
// Do not output empty commands if the whole paragraph has
|
||||||
// been deleted with ct and changes are not output.
|
// been deleted with ct and changes are not output.
|
||||||
if (!runparams_in.for_search && style.latextype != LATEX_ENVIRONMENT
|
if (style.latextype != LATEX_ENVIRONMENT
|
||||||
&& !par.empty() && par.isDeleted(0, par.size()) && !bparams.output_changes)
|
&& !par.empty() && par.isDeleted(0, par.size()) && !bparams.output_changes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1665,7 +1665,7 @@ void latexParagraphs(Buffer const & buf,
|
|||||||
if ((par->layout() != nextpar->layout()
|
if ((par->layout() != nextpar->layout()
|
||||||
|| par->params().depth() == nextpar->params().depth()
|
|| par->params().depth() == nextpar->params().depth()
|
||||||
|| par->params().leftIndent() == nextpar->params().leftIndent())
|
|| par->params().leftIndent() == nextpar->params().leftIndent())
|
||||||
&& !runparams.for_search && !cpar.empty()
|
&& !cpar.empty()
|
||||||
&& cpar.isDeleted(0, cpar.size()) && !bparams.output_changes) {
|
&& cpar.isDeleted(0, cpar.size()) && !bparams.output_changes) {
|
||||||
if (!cpar.parEndChange().deleted())
|
if (!cpar.parEndChange().deleted())
|
||||||
os << '\n' << '\n';
|
os << '\n' << '\n';
|
||||||
@ -1674,7 +1674,7 @@ void latexParagraphs(Buffer const & buf,
|
|||||||
} else {
|
} else {
|
||||||
// This is the last par
|
// This is the last par
|
||||||
Paragraph const & cpar = paragraphs.at(pit);
|
Paragraph const & cpar = paragraphs.at(pit);
|
||||||
if (!runparams.for_search && !cpar.empty()
|
if (!cpar.empty()
|
||||||
&& cpar.isDeleted(0, cpar.size()) && !bparams.output_changes) {
|
&& cpar.isDeleted(0, cpar.size()) && !bparams.output_changes) {
|
||||||
if (!cpar.parEndChange().deleted())
|
if (!cpar.parEndChange().deleted())
|
||||||
os << '\n' << '\n';
|
os << '\n' << '\n';
|
||||||
|
Loading…
Reference in New Issue
Block a user