if (!cur.inTexted())
// bail in math
return make_pair(false, 0);
- // select current word and treat it as the search string
+ // select current word and treat it as the search string.
+ // This causes a minor bug as undo will restore this selection,
+ // which the user did not create (#8986).
cur.innerText()->selectWord(cur, WHOLE_WORD);
searchstr = cur.selectionAsString(false);
}
// of this function). This will avoid changes to be selected half.
bool search_both_sides = false;
Cursor tmpcur = cur;
- // Leave math first
+ // Find enclosing text cursor
while (tmpcur.inMathed())
tmpcur.pop_back();
Change change_next_pos
= tmpcur.paragraph().lookupChange(tmpcur.pos());
- if (change_next_pos.changed() && cur.inMathed()) {
- cur = tmpcur;
- search_both_sides = true;
- } else if (tmpcur.pos() > 0 && tmpcur.inTexted()) {
- Change change_prev_pos
- = tmpcur.paragraph().lookupChange(tmpcur.pos() - 1);
- if (change_next_pos.isSimilarTo(change_prev_pos))
+ if (change_next_pos.changed()) {
+ if (cur.inMathed()) {
+ cur = tmpcur;
search_both_sides = true;
+ } else if (tmpcur.pos() > 0 && tmpcur.inTexted()) {
+ Change change_prev_pos
+ = tmpcur.paragraph().lookupChange(tmpcur.pos() - 1);
+ if (change_next_pos.isSimilarTo(change_prev_pos))
+ search_both_sides = true;
+ }
}
+ // find the next change
if (!findChange(cur, next))
return false;
CursorSlice & tip = cur.top();
- if (!next)
+ if (!next && tip.pos() > 0)
// take a step into the change
tip.backwardPos();
int MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_begin) const
{
+ if (at_begin &&
+ (opt.restr == FindAndReplaceOptions::R_ONLY_MATHS && !cur.inMathed()) )
+ return 0;
docstring docstr = stringifyFromForSearch(opt, cur, len);
LYXERR(Debug::FIND, "Matching against '" << lyx::to_utf8(docstr) << "'");
string str = normalize(docstr, true);
docstring const & find_buf_name, bool casesensitive,
bool matchword, bool forward, bool expandmacros, bool ignoreformat,
docstring const & repl_buf_name, bool keep_case,
- SearchScope scope)
+ SearchScope scope, SearchRestriction restr)
: find_buf_name(find_buf_name), casesensitive(casesensitive), matchword(matchword),
forward(forward), expandmacros(expandmacros), ignoreformat(ignoreformat),
- repl_buf_name(repl_buf_name), keep_case(keep_case), scope(scope)
+ repl_buf_name(repl_buf_name), keep_case(keep_case), scope(scope), restr(restr)
{
}
<< opt.ignoreformat << ' '
<< to_utf8(opt.repl_buf_name) << "\nEOSS\n"
<< opt.keep_case << ' '
- << int(opt.scope);
+ << int(opt.scope) << ' '
+ << int(opt.restr);
LYXERR(Debug::FIND, "built: " << os.str());
int i;
is >> i;
opt.scope = FindAndReplaceOptions::SearchScope(i);
+ is >> i;
+ opt.restr = FindAndReplaceOptions::SearchRestriction(i);
+
LYXERR(Debug::FIND, "parsed: " << opt.casesensitive << ' ' << opt.matchword << ' ' << opt.forward << ' '
- << opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.keep_case);
+ << opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.keep_case << ' '
+ << opt.scope << ' ' << opt.restr);
return is;
}