+ if (opt.replace == docstring(from_utf8(LYX_FR_NULL_STRING))) {
+ bv->message(_("Match found!"));
+ } else {
+ string lyx = to_utf8(opt.replace);
+ // FIXME: Seems so stupid to me to rebuild a buffer here,
+ // when we already have one (replace_work_area_.buffer())
+ Buffer repl_buffer("", false);
+ repl_buffer.setUnnamed(true);
+ if (repl_buffer.readString(lyx)) {
+ if (opt.keep_case && match_len >= 2) {
+ if (cur.inTexted()) {
+ if (firstUppercase(cur))
+ changeFirstCase(repl_buffer, text_uppercase, text_lowercase);
+ else if (allNonLowercase(cur, match_len))
+ changeFirstCase(repl_buffer, text_uppercase, text_uppercase);
+ }
+ }
+ cap::cutSelection(bv->cursor(), false, false);
+ if (! cur.inMathed()) {
+ LYXERR(Debug::FIND, "Replacing by pasteParagraphList()ing repl_buffer");
+ cap::pasteParagraphList(bv->cursor(), repl_buffer.paragraphs(),
+ repl_buffer.params().documentClassPtr(),
+ bv->buffer().errorList("Paste"));
+ } else {
+ odocstringstream ods;
+ OutputParams runparams(&repl_buffer.params().encoding());
+ runparams.nice = false;
+ runparams.flavor = OutputParams::LATEX;
+ runparams.linelen = 8000; //lyxrc.plaintext_linelen;
+ runparams.dryrun = true;
+ TexRow texrow;
+ TeXOnePar(repl_buffer, repl_buffer.text(),
+ repl_buffer.paragraphs().begin(), ods, texrow, runparams);
+ //repl_buffer.getSourceCode(ods, 0, repl_buffer.paragraphs().size(), false);
+ docstring repl_latex = ods.str();
+ LYXERR(Debug::FIND, "Latexified replace_buffer: '" << repl_latex << "'");
+ string s;
+ regex_replace(to_utf8(repl_latex), s, "\\$(.*)\\$", "$1");
+ regex_replace(s, s, "\\\\\\[(.*)\\\\\\]", "$1");
+ repl_latex = from_utf8(s);
+ LYXERR(Debug::FIND, "Replacing by niceInsert()ing latex: '" << repl_latex << "'");
+ bv->cursor().niceInsert(repl_latex);
+ }
+ bv->putSelectionAt(cur, repl_buffer.paragraphs().begin()->size(), ! opt.forward);
+ bv->message(_("Match found and replaced !"));
+ } else
+ LASSERT(false, /**/);
+ }