#include "lyxfind.h"
#include "buffer.h"
+#include "cursor.h"
#include "BufferView.h"
#include "debug.h"
#include "iterators.h"
using lyx::support::uppercase;
using lyx::support::split;
-using bv_funcs::put_selection_at;
-
+using std::advance;
using std::ostringstream;
using std::string;
namespace find {
string const find2string(string const & search,
- bool casesensitive, bool matchword, bool forward)
+ bool casesensitive, bool matchword, bool forward)
{
ostringstream ss;
ss << search << '\n'
return ss.str();
}
-
+
string const replace2string(string const & search, string const & replace,
bool casesensitive, bool matchword,
}
-void find(FuncRequest const & ev)
+void find(BufferView * bv, FuncRequest const & ev)
{
- if (!ev.view() || ev.action != LFUN_WORD_FIND)
+ if (!bv || ev.action != LFUN_WORD_FIND)
return;
// data is of the form
bool matchword = parse_bool(howto);
bool forward = parse_bool(howto);
- BufferView * bv = ev.view();
bool const found = ::find(bv, search,
- forward, casesensitive, matchword);
+ casesensitive, matchword, forward);
if (!found)
bv->owner()->message(_("String not found!"));
}
-void replace(FuncRequest const & ev)
+void replace(BufferView * bv, FuncRequest const & ev)
{
- if (!ev.view() || ev.action != LFUN_WORD_REPLACE)
+ if (!bv || ev.action != LFUN_WORD_REPLACE)
return;
// data is of the form
bool all = parse_bool(howto);
bool forward = parse_bool(howto);
- BufferView * bv = ev.view();
LyXView * lv = bv->owner();
int const replace_count = all ?
casesensitive, matchword) :
::replace(bv, search, replace,
casesensitive, matchword, forward);
-
+
if (replace_count == 0) {
lv->message(_("String not found!"));
} else {
if (!findChange(cur, endit))
return false;
-
+
ParagraphList::iterator pit = cur.pit();
pos_type pos = cur.pos();
-
+
Change orig_change = pit->lookupChangeFull(pos);
pos_type parsize = pit->size();
pos_type end = pos;
}
}
pos_type length = end - pos;
- put_selection_at(bv, cur, length, true);
+ bv->putSelectionAt(cur, length, true);
return true;
}
namespace {
-class MatchString
+class MatchString : public std::binary_function<Paragraph, lyx::pos_type, bool>
{
public:
MatchString(string const & str, bool cs, bool mw)
return true;
}
-
+
private:
// search string
string str;
bool findChange(PosIterator & cur, PosIterator const & end)
{
for (; cur != end; ++cur) {
- if ((!cur.pit()->size() || !cur.at_end())
+ if ((cur.pit()->empty() || !cur.at_end())
&& cur.pit()->lookupChange(cur.pos()) != Change::UNCHANGED)
return true;
}
: findBackwards(cur, beg, match);
if (found)
- put_selection_at(bv, cur, searchstr.length(), !fw);
+ bv->putSelectionAt(cur, searchstr.length(), !fw);
return found;
}
if (!searchAllowed(bv, searchstr) || buf.isReadonly())
return 0;
-
- recordUndo(Undo::ATOMIC, bv->text(), 0, buf.paragraphs().size() - 1);
-
+
+ recordUndoFullDocument(bv->cursor());
+
PosIterator cur = buf.pos_iterator_begin();
PosIterator const end = buf.pos_iterator_end();
MatchString const match(searchstr, cs, mw);
PosIterator beg = buf.pos_iterator_begin();
bv->text()->init(bv);
- put_selection_at(bv, beg, 0, false);
+ bv->putSelectionAt(beg, 0, false);
if (num)
buf.markDirty();
return num;
bool stringSelected(BufferView * bv,
- string const & searchstr,
+ string const & searchstr,
bool cs, bool mw, bool fw)
{
LyXText * text = bv->getLyXText();
text->replaceSelectionWithString(replacestr);
text->setSelectionRange(replacestr.length());
- text->cursor = fw ? text->selEnd() : text->selStart();
-
+ bv->cursor().current() = fw ? bv->cursor().selEnd() : bv->cursor().selBegin();
bv->buffer()->markDirty();
find(bv, searchstr, cs, mw, fw);
bv->update();
-
+
return 1;
}