///
void setIgnoreDeleted(bool value);
///
- void setIgnoreFormat(string const & type, bool value);
+ void setIgnoreFormat(string const & type, bool value, bool fromUser = true);
private:
///
bool ignoreColor_ = false;
///
bool ignoreLanguage_ = false;
+ bool userSelectedIgnoreLanguage_ = false;
///
bool ignoreDeleted_ = true;
};
-void IgnoreFormats::setIgnoreFormat(string const & type, bool value)
+void IgnoreFormats::setIgnoreFormat(string const & type, bool value, bool fromUser)
{
if (type == "color") {
ignoreColor_ = value;
}
else if (type == "language") {
- ignoreLanguage_ = value;
+ if (fromUser) {
+ userSelectedIgnoreLanguage_ = value;
+ ignoreLanguage_ = value;
+ }
+ else
+ ignoreLanguage_ = (value || userSelectedIgnoreLanguage_);
}
else if (type == "sectioning") {
ignoreSectioning_ = value;
IgnoreFormats ignoreFormats;
-void setIgnoreFormat(string const & type, bool value)
+void setIgnoreFormat(string const & type, bool value, bool fromUser)
{
- ignoreFormats.setIgnoreFormat(type, value);
+ ignoreFormats.setIgnoreFormat(type, value, fromUser);
}
namespace {
-bool parse_bool(docstring & howto)
+bool parse_bool(docstring & howto, bool const defvalue = false)
{
if (howto.empty())
- return false;
+ return defvalue;
docstring var;
howto = split(howto, var, ' ');
return var == "1";
return true;
}
+} // namespace
+
bool findOne(BufferView * bv, docstring const & searchstr,
bool case_sens, bool whole, bool forward,
- bool find_del = true, bool check_wrap = false)
+ bool find_del, bool check_wrap, bool auto_wrap,
+ bool instant)
{
if (!searchAllowed(searchstr))
return false;
DocIterator cur = forward
- ? bv->cursor().selectionEnd()
- : bv->cursor().selectionBegin();
+ ? (instant ? bv->cursor().selectionBegin() : bv->cursor().selectionEnd())
+ : (instant ? bv->cursor().selectionEnd() : bv->cursor().selectionBegin());
MatchString const match(searchstr, case_sens, whole);
bv->putSelectionAt(cur, match_len, !forward);
else if (check_wrap) {
DocIterator cur_orig(bv->cursor());
- docstring q;
- if (forward)
- q = _("End of file reached while searching forward.\n"
- "Continue searching from the beginning?");
- else
- q = _("Beginning of file reached while searching backward.\n"
- "Continue searching from the end?");
- int wrap_answer = frontend::Alert::prompt(_("Wrap search?"),
- q, 0, 1, _("&Yes"), _("&No"));
- if (wrap_answer == 0) {
+ if (!auto_wrap) {
+ docstring q;
+ if (forward)
+ q = _("End of file reached while searching forward.\n"
+ "Continue searching from the beginning?");
+ else
+ q = _("Beginning of file reached while searching backward.\n"
+ "Continue searching from the end?");
+ int wrap_answer = frontend::Alert::prompt(_("Wrap search?"),
+ q, 0, 1, _("&Yes"), _("&No"));
+ auto_wrap = wrap_answer == 0;
+ }
+ if (auto_wrap) {
if (forward) {
bv->cursor().clear();
bv->cursor().push_back(CursorSlice(bv->buffer().inset()));
bv->cursor().backwardPos();
}
bv->clearSelection();
- if (findOne(bv, searchstr, case_sens, whole, forward, find_del, false))
+ if (findOne(bv, searchstr, case_sens, whole, forward,
+ find_del, false, false, false))
return true;
}
bv->cursor().setCursor(cur_orig);
}
+namespace {
+
int replaceAll(BufferView * bv,
docstring const & searchstr, docstring const & replacestr,
bool case_sens, bool whole)
// whether anything at all was done.
pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
docstring const & replacestr, bool case_sens,
- bool whole, bool forward, bool findnext)
+ bool whole, bool forward, bool findnext, bool wrap)
{
Cursor & cur = bv->cursor();
if (!cur.selection()) {
// no selection, non-empty search string: find it
if (!searchstr.empty()) {
- bool const found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
+ bool const found = findOne(bv, searchstr, case_sens, whole,
+ forward, true, findnext, wrap, false);
return make_pair(found, 0);
}
// empty search string
// no selection or current selection is not search word:
// just find the search word
if (!have_selection || !match) {
- bool const found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext);
+ bool const found = findOne(bv, searchstr, case_sens, whole, forward,
+ true, findnext, wrap, false);
return make_pair(found, 0);
}
cur.pos() = cur.lastpos());
}
if (findnext)
- findOne(bv, searchstr, case_sens, whole, forward, false, findnext);
+ findOne(bv, searchstr, case_sens, whole,
+ forward, false, findnext, wrap, false);
return make_pair(true, 1);
}
docstring const find2string(docstring const & search,
- bool casesensitive, bool matchword, bool forward)
+ bool casesensitive, bool matchword,
+ bool forward, bool wrap, bool instant)
{
odocstringstream ss;
ss << search << '\n'
<< int(casesensitive) << ' '
<< int(matchword) << ' '
- << int(forward);
+ << int(forward) << ' '
+ << int(wrap) << ' '
+ << int(instant);
return ss.str();
}
docstring const replace2string(docstring const & replace,
docstring const & search,
bool casesensitive, bool matchword,
- bool all, bool forward, bool findnext)
+ bool all, bool forward, bool findnext, bool wrap)
{
odocstringstream ss;
ss << replace << '\n'
<< int(matchword) << ' '
<< int(all) << ' '
<< int(forward) << ' '
- << int(findnext);
+ << int(findnext) << ' '
+ << int(wrap);
return ss.str();
}
-bool lyxfind(BufferView * bv, FuncRequest const & ev)
+docstring const string2find(docstring const & argument,
+ bool &casesensitive,
+ bool &matchword,
+ bool &forward,
+ bool &wrap,
+ bool &instant)
{
- if (!bv || ev.action() != LFUN_WORD_FIND)
- return false;
-
- //lyxerr << "find called, cmd: " << ev << endl;
-
// data is of the form
// "<search>
- // <casesensitive> <matchword> <forward>"
+ // <casesensitive> <matchword> <forward> <wrap>"
docstring search;
- docstring howto = split(ev.argument(), search, '\n');
+ docstring howto = split(argument, search, '\n');
- bool casesensitive = parse_bool(howto);
- bool matchword = parse_bool(howto);
- bool forward = parse_bool(howto);
+ casesensitive = parse_bool(howto);
+ matchword = parse_bool(howto);
+ forward = parse_bool(howto, true);
+ wrap = parse_bool(howto);
+ instant = parse_bool(howto);
+
+ return search;
+}
+
+
+bool lyxfind(BufferView * bv, FuncRequest const & ev)
+{
+ if (!bv || ev.action() != LFUN_WORD_FIND)
+ return false;
- return findOne(bv, search, casesensitive, matchword, forward, false, true);
+ //lyxerr << "find called, cmd: " << ev << endl;
+ bool casesensitive;
+ bool matchword;
+ bool forward;
+ bool wrap;
+ bool instant;
+
+ docstring search = string2find(ev.argument(), casesensitive,
+ matchword, forward, wrap, instant);
+
+ return findOne(bv, search, casesensitive, matchword, forward,
+ false, true, wrap, instant);
}
// data is of the form
// "<search>
// <replace>
- // <casesensitive> <matchword> <all> <forward> <findnext>"
+ // <casesensitive> <matchword> <all> <forward> <findnext> <wrap>"
docstring search;
docstring rplc;
docstring howto = split(ev.argument(), rplc, '\n');
bool casesensitive = parse_bool(howto);
bool matchword = parse_bool(howto);
bool all = parse_bool(howto);
- bool forward = parse_bool(howto);
- bool findnext = howto.empty() ? true : parse_bool(howto);
+ bool forward = parse_bool(howto, true);
+ bool findnext = parse_bool(howto, true);
+ bool wrap = parse_bool(howto);
bool update = false;
update = replace_count > 0;
} else {
pair<bool, int> rv =
- replaceOne(bv, search, rplc, casesensitive, matchword, forward, findnext);
+ replaceOne(bv, search, rplc, casesensitive, matchword, forward, findnext, wrap);
update = rv.first;
replace_count = rv.second;
}
public:
string wait;
size_t mathEnd;
+ size_t mathpostfixsize;
size_t mathStart;
+ size_t mathprefixsize;
size_t mathSize;
};
size_t actualIdx_;
MathInfo() {
actualIdx_ = 0;
}
- void insert(string const & wait, size_t start, size_t end) {
+ void insert(string const & wait, size_t start, size_t prefixsize, size_t end, size_t postfixsize) {
MathEntry m = MathEntry();
m.wait = wait;
m.mathStart = start;
- m.mathEnd = end;
- m.mathSize = end - start;
+ m.mathprefixsize = prefixsize;
+ m.mathEnd = end + postfixsize;
+ m.mathpostfixsize = postfixsize;
+ m.mathSize = m.mathEnd - m.mathStart;
entries_.push_back(m);
}
bool empty() const { return entries_.empty(); };
}
return entries_[actualIdx_].mathStart;
}
+ size_t getPrefixSize() const {
+ if (entries_.empty() || (actualIdx_ >= entries_.size())) {
+ return 0;
+ }
+ return entries_[actualIdx_].mathprefixsize;
+ }
+ size_t getPostfixSize() const {
+ if (entries_.empty() || (actualIdx_ >= entries_.size())) {
+ return 0;
+ }
+ return entries_[actualIdx_].mathpostfixsize;
+ }
size_t getFirstPos() {
actualIdx_ = 0;
return getStartPos();
KeyInfo found;
bool math_end_waiting = false;
size_t math_pos = 10000;
+ size_t math_prefix_size = 1;
string math_end;
static vector<string> usedText = vector<string>();
+ static bool removeMathHull = false;
interval_.removeAccents();
size_t pos = submath.position(size_t(2));
if ((math_end == "$") &&
(submath.str(2) == "$")) {
- mi.insert("$", math_pos, pos + 1);
+ mi.insert("$", math_pos, 1, pos, 1);
math_end_waiting = false;
}
else if ((math_end == "\\]") &&
(submath.str(2) == "\\]")) {
- mi.insert("\\]", math_pos, pos + 2);
+ mi.insert("\\]", math_pos, 2, pos, 2);
math_end_waiting = false;
}
else if ((submath.str(3).compare("end") == 0) &&
(submath.str(4).compare(math_end) == 0)) {
- mi.insert(math_end, math_pos, pos + submath.str(2).length());
+ mi.insert(math_end, math_pos, math_prefix_size, pos, submath.str(2).length());
math_end_waiting = false;
}
else
math_end_waiting = true;
math_end = submath.str(4);
math_pos = submath.position(size_t(2));
+ math_prefix_size = submath.str(2).length();
}
else if (submath.str(2).compare("\\[") == 0) {
math_end_waiting = true;
// Disable language
keys["foreignlanguage"].disabled = true;
disableLanguageOverride = true;
+ removeMathHull = false;
}
- else
+ else {
+ removeMathHull = true; // used later if not isPatternString
disableLanguageOverride = false;
+ }
}
else {
if (disableLanguageOverride) {
found._dataStart = found._dataEnd;
found.parenthesiscount = 0;
found.head = interval_.par.substr(found._tokenstart, found._tokensize);
+ if (removeMathHull) {
+ interval_.addIntervall(found._tokenstart, found._tokenstart + mi.getPrefixSize());
+ interval_.addIntervall(found._dataEnd - mi.getPostfixSize(), found._dataEnd);
+ }
evaluatingMath = true;
}
else {
}
if (dstart < output_end)
interval_.output(os, output_end);
- interval_.addIntervall(actual._tokenstart, end);
+ if (nextKeyIdx < 0)
+ interval_.addIntervall(0, end);
+ else
+ interval_.addIntervall(actual._tokenstart, end);
return nextKeyIdx;
}
break;
}
}
- setIgnoreFormat("language", toIgnoreLang);
+ setIgnoreFormat("language", toIgnoreLang, false);
}
result = splitOnKnownMacros(par.substr(0,parlen), isPatternString);
LYXERR(Debug::FIND, "Before pasteParagraphList() cur=" << cur << endl);
cap::pasteParagraphList(cur, repl_buffer.paragraphs(),
repl_buffer.params().documentClassPtr(),
+ repl_buffer.params().authors(),
bv->buffer().errorList("Paste"));
LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << endl);
sel_len = repl_buffer.paragraphs().begin()->size();