#include "frontends/Alert.h"
#include "frontends/LyXView.h"
-#include "support/textutils.h"
-#include "support/tostr.h"
+#include "support/convert.h"
-#include "support/std_sstream.h"
+#include <sstream>
using lyx::support::lowercase;
using lyx::support::uppercase;
using lyx::support::split;
-using lyx::par_type;
+using lyx::pit_type;
using lyx::pos_type;
using std::advance;
for (i = 0; pos + i < parsize; ++i) {
if (string::size_type(i) >= size)
break;
- if (cs && str[i] != par.getChar(pos + i))
+ if (cs && str[i] != par.getChar(pos + i))
break;
if (!cs && uppercase(str[i]) != uppercase(par.getChar(pos + i)))
break;
// if necessary, check whether string matches word
if (mw) {
- if (pos > 0 && IsLetterCharOrDigit(par.getChar(pos - 1)))
+ if (pos > 0 && par.isLetter(pos - 1))
return false;
if (pos + lyx::pos_type(size) < parsize
- && IsLetterCharOrDigit(par.getChar(pos + size)));
+ && par.isLetter(pos + size))
return false;
}
};
-bool findForward(DocumentIterator & cur, MatchString const & match)
+bool findForward(DocIterator & cur, MatchString const & match)
{
- for (; cur.size(); cur.forwardChar())
- if (match(cur.paragraph(), cur.pos()))
+ for (; cur; cur.forwardChar())
+ if (cur.inTexted() && match(cur.paragraph(), cur.pos()))
return true;
return false;
}
-bool findBackwards(DocumentIterator & cur, MatchString const & match)
+bool findBackwards(DocIterator & cur, MatchString const & match)
{
- for (; cur.size(); cur.backwardChar())
- if (match(cur.paragraph(), cur.pos()))
+ while (cur) {
+ cur.backwardChar();
+ if (cur.inTexted() && match(cur.paragraph(), cur.pos()))
return true;
+ }
return false;
}
-bool findChange(DocumentIterator & cur)
+bool findChange(DocIterator & cur)
{
- for (; cur.size(); cur.forwardChar())
- if ((cur.paragraph().empty() || !cur.empty())
- && cur.paragraph().lookupChange(cur.pos()) != Change::UNCHANGED)
+ for (; cur; cur.forwardPos())
+ if (cur.inTexted() && cur.paragraph().lookupChange(cur.pos())
+ != Change::UNCHANGED)
return true;
return false;
}
if (!searchAllowed(bv, searchstr))
return false;
- DocumentIterator cur = bv->cursor();
+ DocIterator cur = bv->cursor();
MatchString const match(searchstr, cs, mw);
if (!searchAllowed(bv, searchstr) || buf.isReadonly())
return 0;
- recordUndoFullDocument(bv->cursor());
+ recordUndoFullDocument(bv);
MatchString const match(searchstr, cs, mw);
int num = 0;
int const rsize = replacestr.size();
int const ssize = searchstr.size();
- DocumentIterator cur = DocumentIterator(buf.inset());
+ DocIterator cur = doc_iterator_begin(buf.inset());
while (findForward(cur, match)) {
lyx::pos_type pos = cur.pos();
LyXFont const font
}
bv->text()->init(bv);
- bv->putSelectionAt(DocumentIterator(buf.inset()), 0, false);
+ bv->putSelectionAt(doc_iterator_begin(buf.inset()), 0, false);
if (num)
buf.markDirty();
return num;
int replace(BufferView * bv, string const & searchstr,
- string const & replacestr, bool cs, bool mw, bool fw)
+ string const & replacestr, bool cs, bool mw, bool fw)
{
if (!searchAllowed(bv, searchstr) || bv->buffer()->isReadonly())
return 0;
if (replace_count == 1) {
lv->message(_("String has been replaced."));
} else {
- string str = tostr(replace_count);
+ string str = convert<string>(replace_count);
str += _(" strings have been replaced.");
lv->message(str);
}
if (!bv->available())
return false;
- DocumentIterator cur = DocumentIterator(bv->buffer()->inset());
+ DocIterator cur = bv->cursor();
if (!findChange(cur))
return false;
- Paragraph const & par = cur.paragraph();
- pos_type pos = cur.pos();
+ bv->cursor().setCursor(cur);
+ bv->cursor().resetAnchor();
- Change orig_change = par.lookupChangeFull(pos);
- pos_type parsize = par.size();
- pos_type end = pos;
+ Change orig_change = cur.paragraph().lookupChangeFull(cur.pos());
- for (; end != parsize; ++end) {
- Change change = par.lookupChangeFull(end);
+ DocIterator et = doc_iterator_end(cur.inset());
+ for (; cur != et; cur.forwardPosNoDescend()) {
+ Change change = cur.paragraph().lookupChangeFull(cur.pos());
if (change != orig_change) {
- // slight UI optimisation: for replacements, we get
- // text like : _old_new. Consider that as one change.
- if (!(orig_change.type == Change::DELETED &&
- change.type == Change::INSERTED))
- break;
+ break;
}
}
- pos_type length = end - pos;
- bv->putSelectionAt(cur, length, true);
+ // Now put cursor to end of selection:
+ bv->cursor().setCursor(cur);
+ bv->cursor().setSelection();
+ // if we used a lfun like in find/replace, dispatch would do
+ // that for us
+ bv->update();
+
return true;
}
} // find namespace
} // lyx namespace
-
-