2001-03-06 10:20:33 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "lyxfind.h"
|
2002-08-08 21:08:02 +00:00
|
|
|
#include "paragraph.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2001-11-26 10:19:58 +00:00
|
|
|
#include "frontends/Alert.h"
|
2001-03-06 10:20:33 +00:00
|
|
|
#include "support/textutils.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "buffer.h"
|
2001-12-10 12:50:09 +00:00
|
|
|
#include "debug.h"
|
2001-04-17 15:15:59 +00:00
|
|
|
#include "gettext.h"
|
2002-07-26 09:50:16 +00:00
|
|
|
#include "insets/insettext.h"
|
2003-02-08 19:18:01 +00:00
|
|
|
#include "changes.h"
|
2001-03-06 10:20:33 +00:00
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
using lyx::pos_type;
|
2003-02-08 19:18:01 +00:00
|
|
|
using std::endl;
|
2001-11-27 10:34:16 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
namespace lyxfind {
|
2001-07-20 14:18:48 +00:00
|
|
|
|
|
|
|
/// returns true if the specified string is at the specified position
|
2001-11-27 10:34:16 +00:00
|
|
|
bool IsStringInText(Paragraph * par, pos_type pos,
|
2002-03-21 17:27:08 +00:00
|
|
|
string const & str, bool const & = true,
|
|
|
|
bool const & = false);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
|
|
|
/// if the string is found: return true and set the cursor to the new position
|
|
|
|
SearchResult SearchForward(BufferView *, LyXText * text, string const & str,
|
2002-03-21 17:27:08 +00:00
|
|
|
bool const & = true, bool const & = false);
|
2001-07-20 14:18:48 +00:00
|
|
|
///
|
|
|
|
SearchResult SearchBackward(BufferView *, LyXText * text, string const & str,
|
2002-03-21 17:27:08 +00:00
|
|
|
bool const & = true, bool const & = false);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
2001-03-06 10:20:33 +00:00
|
|
|
int LyXReplace(BufferView * bv,
|
2002-03-21 17:27:08 +00:00
|
|
|
string const & searchstr, string const & replacestr,
|
|
|
|
bool forward, bool casesens, bool matchwrd, bool replaceall,
|
|
|
|
bool once)
|
2001-03-06 10:20:33 +00:00
|
|
|
{
|
2002-03-21 17:27:08 +00:00
|
|
|
if (!bv->available() || bv->buffer()->isReadonly())
|
2001-07-20 14:18:48 +00:00
|
|
|
return 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
// CutSelection cannot cut a single space, so we have to stop
|
|
|
|
// in order to avoid endless loop :-(
|
|
|
|
if (searchstr.length() == 0
|
2003-03-29 10:29:38 +00:00
|
|
|
|| (searchstr.length() == 1 && searchstr[0] == ' ')) {
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning BLECH. If we have an LFUN for replace, we can fix this bogosity
|
|
|
|
#endif
|
|
|
|
Alert::error(_("Cannot replace"),
|
|
|
|
_("You cannot replace a single space or "
|
|
|
|
"an empty character."));
|
2001-07-20 14:18:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
// now we can start searching for the first
|
2001-07-20 14:18:48 +00:00
|
|
|
// start at top if replaceall
|
2002-06-18 15:44:30 +00:00
|
|
|
LyXText * text = bv->getLyXText();
|
2001-07-20 14:18:48 +00:00
|
|
|
bool fw = forward;
|
|
|
|
if (replaceall) {
|
2001-08-01 15:42:53 +00:00
|
|
|
text->clearSelection();
|
2002-06-18 15:44:30 +00:00
|
|
|
bv->unlockInset(bv->theLockingInset());
|
|
|
|
text = bv->text;
|
2003-03-17 16:25:00 +00:00
|
|
|
text->cursorTop();
|
2001-07-20 14:18:48 +00:00
|
|
|
// override search direction because we search top to bottom
|
|
|
|
fw = true;
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
// if nothing selected or selection does not equal search string
|
|
|
|
// search and select next occurance and return if no replaceall
|
2001-08-13 10:09:50 +00:00
|
|
|
string str1;
|
|
|
|
string str2;
|
|
|
|
if (casesens) {
|
|
|
|
str1 = searchstr;
|
2001-09-12 10:41:25 +00:00
|
|
|
str2 = text->selectionAsString(bv->buffer(), false);
|
2001-08-13 10:09:50 +00:00
|
|
|
} else {
|
|
|
|
str1 = lowercase(searchstr);
|
2001-09-12 10:41:25 +00:00
|
|
|
str2 = lowercase(text->selectionAsString(bv->buffer(), false));
|
2001-08-13 10:09:50 +00:00
|
|
|
}
|
|
|
|
if (str1 != str2) {
|
2002-06-18 15:44:30 +00:00
|
|
|
if (!LyXFind(bv, searchstr, fw, casesens, matchwrd) ||
|
2001-07-20 14:18:48 +00:00
|
|
|
!replaceall)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2001-08-13 10:09:50 +00:00
|
|
|
|
2001-08-01 15:42:53 +00:00
|
|
|
bool found = false;
|
2001-07-20 14:18:48 +00:00
|
|
|
int replace_count = 0;
|
|
|
|
do {
|
2002-06-18 15:44:30 +00:00
|
|
|
text = bv->getLyXText();
|
2002-07-26 09:50:16 +00:00
|
|
|
// We have to do this check only because mathed insets don't
|
|
|
|
// return their own LyXText but the LyXText of it's parent!
|
|
|
|
if (!bv->theLockingInset() ||
|
|
|
|
((text != bv->text) &&
|
|
|
|
(text->inset_owner == text->inset_owner->getLockingInset())))
|
|
|
|
{
|
2002-07-25 15:42:35 +00:00
|
|
|
bv->hideCursor();
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(text, BufferView::SELECT);
|
2002-07-25 15:42:35 +00:00
|
|
|
bv->toggleSelection(false);
|
2003-03-17 16:25:00 +00:00
|
|
|
text->replaceSelectionWithString(replacestr);
|
|
|
|
text->setSelectionRange(replacestr.length());
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(text, BufferView::SELECT);
|
2002-07-25 15:42:35 +00:00
|
|
|
++replace_count;
|
|
|
|
}
|
2001-07-29 10:42:11 +00:00
|
|
|
if (!once)
|
2002-06-18 15:44:30 +00:00
|
|
|
found = LyXFind(bv, searchstr, fw, casesens, matchwrd);
|
2001-07-29 10:42:11 +00:00
|
|
|
} while (!once && replaceall && found);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-03-19 14:45:22 +00:00
|
|
|
// FIXME: should be called via an LFUN
|
|
|
|
bv->buffer()->markDirty();
|
|
|
|
bv->fitCursor();
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
return replace_count;
|
2001-03-06 10:20:33 +00:00
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2001-03-06 10:20:33 +00:00
|
|
|
|
|
|
|
bool LyXFind(BufferView * bv,
|
2002-03-21 17:27:08 +00:00
|
|
|
string const & searchstr, bool forward,
|
2002-06-18 15:44:30 +00:00
|
|
|
bool casesens, bool matchwrd)
|
2001-03-06 10:20:33 +00:00
|
|
|
{
|
2001-07-20 14:18:48 +00:00
|
|
|
if (!bv->available() || searchstr.empty())
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
bv->hideCursor();
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(bv->getLyXText(), BufferView::SELECT);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
if (bv->theLockingInset()) {
|
2001-07-20 14:18:48 +00:00
|
|
|
bool found = forward ?
|
|
|
|
bv->theLockingInset()->searchForward(bv, searchstr, casesens, matchwrd) :
|
|
|
|
bv->theLockingInset()->searchBackward(bv, searchstr, casesens, matchwrd);
|
2002-06-18 15:44:30 +00:00
|
|
|
// We found the stuff inside the inset so we don't have to
|
|
|
|
// do anything as the inset did all the update for us!
|
2001-07-20 14:18:48 +00:00
|
|
|
if (found)
|
2002-06-18 15:44:30 +00:00
|
|
|
return true;
|
|
|
|
// We now are in the main text but if we did a forward
|
|
|
|
// search we have to put the cursor behind the inset.
|
|
|
|
if (forward) {
|
2003-03-17 16:25:00 +00:00
|
|
|
bv->text->cursorRight(true);
|
2001-08-01 15:42:53 +00:00
|
|
|
}
|
2001-07-20 14:18:48 +00:00
|
|
|
}
|
2002-06-18 15:44:30 +00:00
|
|
|
// If we arrive here we are in the main text again so we
|
|
|
|
// just start searching from the root LyXText at the position
|
|
|
|
// we are!
|
|
|
|
LyXText * text = bv->text;
|
|
|
|
|
2003-04-08 00:02:32 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
if (text->selection.set())
|
|
|
|
text->cursor = forward ?
|
|
|
|
text->selection.end : text->selection.start;
|
|
|
|
|
|
|
|
bv->toggleSelection();
|
|
|
|
text->clearSelection();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
SearchResult result = forward ?
|
|
|
|
SearchForward(bv, text, searchstr, casesens, matchwrd) :
|
|
|
|
SearchBackward(bv, text, searchstr, casesens, matchwrd);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
|
|
|
bool found = true;
|
2002-06-18 15:44:30 +00:00
|
|
|
// If we found the cursor inside an inset we will get back
|
|
|
|
// SR_FOUND_NOUPDATE and we don't have to do anything as the
|
|
|
|
// inset did it already.
|
2001-07-20 14:18:48 +00:00
|
|
|
if (result == SR_FOUND) {
|
2002-06-18 15:44:30 +00:00
|
|
|
bv->unlockInset(bv->theLockingInset());
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(text, BufferView::SELECT);
|
2003-03-17 16:25:00 +00:00
|
|
|
text->setSelectionRange(searchstr.length());
|
2001-07-20 14:18:48 +00:00
|
|
|
bv->toggleSelection(false);
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(text, BufferView::SELECT);
|
2002-04-12 09:02:21 +00:00
|
|
|
} else if (result == SR_NOT_FOUND) {
|
2002-06-18 15:44:30 +00:00
|
|
|
bv->unlockInset(bv->theLockingInset());
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(text, BufferView::SELECT);
|
2001-07-20 14:18:48 +00:00
|
|
|
found = false;
|
2002-04-12 09:02:21 +00:00
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->fitCursor();
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
return found;
|
2001-03-06 10:20:33 +00:00
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2001-03-06 10:20:33 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
SearchResult LyXFind(BufferView * bv, LyXText * text,
|
|
|
|
string const & searchstr, bool forward,
|
|
|
|
bool casesens, bool matchwrd)
|
|
|
|
{
|
|
|
|
if (text->selection.set())
|
|
|
|
text->cursor = forward ?
|
|
|
|
text->selection.end : text->selection.start;
|
|
|
|
|
|
|
|
bv->toggleSelection();
|
|
|
|
text->clearSelection();
|
|
|
|
|
|
|
|
SearchResult result = forward ?
|
|
|
|
SearchForward(bv, text, searchstr, casesens, matchwrd) :
|
|
|
|
SearchBackward(bv, text, searchstr, casesens, matchwrd);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-03-06 10:20:33 +00:00
|
|
|
|
|
|
|
// returns true if the specified string is at the specified position
|
2001-11-27 10:34:16 +00:00
|
|
|
bool IsStringInText(Paragraph * par, pos_type pos,
|
2001-03-06 11:05:15 +00:00
|
|
|
string const & str, bool const & cs,
|
|
|
|
bool const & mw)
|
2001-03-06 10:20:33 +00:00
|
|
|
{
|
|
|
|
if (!par)
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-03-06 10:20:33 +00:00
|
|
|
string::size_type size = str.length();
|
2001-11-27 10:34:16 +00:00
|
|
|
pos_type i = 0;
|
2001-03-11 00:21:13 +00:00
|
|
|
while (((pos + i) < par->size())
|
2001-03-06 10:20:33 +00:00
|
|
|
&& (string::size_type(i) < size)
|
2001-06-25 00:06:33 +00:00
|
|
|
&& (cs ? (str[i] == par->getChar(pos + i))
|
2002-03-21 17:27:08 +00:00
|
|
|
: (uppercase(str[i]) == uppercase(par->getChar(pos + i)))))
|
2001-03-06 10:20:33 +00:00
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (size == string::size_type(i)) {
|
2001-07-20 14:18:48 +00:00
|
|
|
// if necessary, check whether string matches word
|
2001-11-26 10:19:58 +00:00
|
|
|
if (!mw)
|
|
|
|
return true;
|
|
|
|
if ((pos <= 0 || !IsLetterCharOrDigit(par->getChar(pos - 1)))
|
2001-11-27 10:34:16 +00:00
|
|
|
&& (pos + pos_type(size) >= par->size()
|
2001-11-26 10:19:58 +00:00
|
|
|
|| !IsLetterCharOrDigit(par->getChar(pos + size)))) {
|
2001-07-20 14:18:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-03-06 10:20:33 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// forward search:
|
|
|
|
// if the string can be found: return true and set the cursor to
|
|
|
|
// the new position, cs = casesensitive, mw = matchword
|
2001-07-20 14:18:48 +00:00
|
|
|
SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str,
|
2002-03-21 17:27:08 +00:00
|
|
|
bool const & cs, bool const & mw)
|
2001-03-06 10:20:33 +00:00
|
|
|
{
|
2003-04-09 09:15:20 +00:00
|
|
|
Paragraph * par = &*text->cursor.par();
|
2001-11-27 10:34:16 +00:00
|
|
|
pos_type pos = text->cursor.pos();
|
2001-07-20 14:18:48 +00:00
|
|
|
UpdatableInset * inset;
|
|
|
|
|
2001-03-06 10:20:33 +00:00
|
|
|
while (par && !IsStringInText(par, pos, str, cs, mw)) {
|
2003-04-09 09:15:20 +00:00
|
|
|
if (pos < par->size()
|
|
|
|
&& par->isInset(pos)
|
|
|
|
&& (inset = (UpdatableInset *)par->getInset(pos))
|
2003-04-08 00:02:32 +00:00
|
|
|
&& inset->isTextInset()
|
|
|
|
&& inset->searchForward(bv, str, cs, mw))
|
|
|
|
return SR_FOUND_NOUPDATE;
|
|
|
|
|
|
|
|
if (++pos >= par->size()) {
|
2001-03-09 00:56:42 +00:00
|
|
|
par = par->next();
|
2001-12-10 12:50:09 +00:00
|
|
|
pos = 0;
|
2001-03-06 10:20:33 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-03-06 10:20:33 +00:00
|
|
|
if (par) {
|
2003-03-17 16:25:00 +00:00
|
|
|
text->setCursor(par, pos);
|
2001-07-20 14:18:48 +00:00
|
|
|
return SR_FOUND;
|
2003-04-08 00:02:32 +00:00
|
|
|
} else
|
2001-07-20 14:18:48 +00:00
|
|
|
return SR_NOT_FOUND;
|
2001-03-06 10:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// backward search:
|
|
|
|
// if the string can be found: return true and set the cursor to
|
|
|
|
// the new position, cs = casesensitive, mw = matchword
|
2001-07-20 14:18:48 +00:00
|
|
|
SearchResult SearchBackward(BufferView * bv, LyXText * text,
|
2002-03-21 17:27:08 +00:00
|
|
|
string const & str,
|
|
|
|
bool const & cs, bool const & mw)
|
2001-03-06 10:20:33 +00:00
|
|
|
{
|
2003-04-09 09:15:20 +00:00
|
|
|
Paragraph * par = &*text->cursor.par();
|
2001-11-27 10:34:16 +00:00
|
|
|
pos_type pos = text->cursor.pos();
|
2001-03-06 10:20:33 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
if (pos > 0)
|
|
|
|
--pos;
|
|
|
|
else {
|
|
|
|
// We skip empty paragraphs (Asger)
|
|
|
|
do {
|
2001-03-09 00:56:42 +00:00
|
|
|
par = par->previous();
|
2001-03-06 10:20:33 +00:00
|
|
|
if (par)
|
2001-03-11 00:21:13 +00:00
|
|
|
pos = par->size() - 1;
|
2001-03-06 10:20:33 +00:00
|
|
|
} while (par && pos < 0);
|
|
|
|
}
|
2001-07-20 14:18:48 +00:00
|
|
|
UpdatableInset * inset;
|
2003-04-09 09:15:20 +00:00
|
|
|
if (par && par->isInset(pos)
|
|
|
|
&& (inset = (UpdatableInset *)par->getInset(pos))
|
2003-04-08 00:02:32 +00:00
|
|
|
&& inset->isTextInset()
|
|
|
|
&& inset->searchBackward(bv, str, cs, mw))
|
|
|
|
return SR_FOUND_NOUPDATE;
|
2001-03-06 10:20:33 +00:00
|
|
|
} while (par && !IsStringInText(par, pos, str, cs, mw));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-03-06 10:20:33 +00:00
|
|
|
if (par) {
|
2003-03-17 16:25:00 +00:00
|
|
|
text->setCursor(par, pos);
|
2001-07-20 14:18:48 +00:00
|
|
|
return SR_FOUND;
|
2003-04-08 00:02:32 +00:00
|
|
|
} else
|
2001-12-10 12:50:09 +00:00
|
|
|
return SR_NOT_FOUND;
|
2001-03-06 10:20:33 +00:00
|
|
|
}
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
SearchResult nextChange(BufferView * bv, LyXText * text, pos_type & length)
|
|
|
|
{
|
2003-04-09 09:15:20 +00:00
|
|
|
Paragraph * par = &*text->cursor.par();
|
2003-02-08 19:18:01 +00:00
|
|
|
pos_type pos = text->cursor.pos();
|
|
|
|
Paragraph * prev_par = par;
|
|
|
|
UpdatableInset * inset;
|
|
|
|
|
|
|
|
while (par) {
|
|
|
|
if ((!par->size() || pos != par->size())
|
|
|
|
&& par->lookupChange(pos) != Change::UNCHANGED)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (par->isInset(pos) &&
|
|
|
|
(inset = (UpdatableInset *)par->getInset(pos)) &&
|
|
|
|
(inset->isTextInset())) {
|
|
|
|
if (inset->nextChange(bv, length))
|
|
|
|
return SR_FOUND_NOUPDATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
++pos;
|
|
|
|
|
|
|
|
if (pos >= par->size()) {
|
|
|
|
prev_par = par;
|
|
|
|
par = par->next();
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (par) {
|
2003-03-17 16:25:00 +00:00
|
|
|
text->setCursor(par, pos);
|
2003-02-08 19:18:01 +00:00
|
|
|
Change orig_change = par->lookupChangeFull(pos);
|
|
|
|
pos_type end = pos;
|
|
|
|
|
|
|
|
for (; end != par->size(); ++end) {
|
|
|
|
Change change = par->lookupChangeFull(end);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
length = end - pos;
|
|
|
|
return SR_FOUND;
|
|
|
|
} else {
|
|
|
|
// make sure we end up at the end of the text,
|
|
|
|
// not the start point of the last search
|
2003-03-17 16:25:00 +00:00
|
|
|
text->setCursor(prev_par, prev_par->size());
|
2003-02-08 19:18:01 +00:00
|
|
|
return SR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
SearchResult findNextChange(BufferView * bv, LyXText * text, pos_type & length)
|
|
|
|
{
|
|
|
|
if (text->selection.set())
|
|
|
|
text->cursor = text->selection.end;
|
|
|
|
|
|
|
|
bv->toggleSelection();
|
|
|
|
text->clearSelection();
|
|
|
|
|
|
|
|
return nextChange(bv, text, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool findNextChange(BufferView * bv)
|
|
|
|
{
|
|
|
|
if (!bv->available())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bv->hideCursor();
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(bv->getLyXText(), BufferView::SELECT);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
pos_type length;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
if (bv->theLockingInset()) {
|
|
|
|
bool found = bv->theLockingInset()->nextChange(bv, length);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
// We found the stuff inside the inset so we don't have to
|
|
|
|
// do anything as the inset did all the update for us!
|
|
|
|
if (found)
|
|
|
|
return true;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
// We now are in the main text but if we did a forward
|
|
|
|
// search we have to put the cursor behind the inset.
|
2003-03-17 16:25:00 +00:00
|
|
|
bv->text->cursorRight(true);
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
|
|
|
// If we arrive here we are in the main text again so we
|
|
|
|
// just start searching from the root LyXText at the position
|
|
|
|
// we are!
|
|
|
|
LyXText * text = bv->text;
|
|
|
|
|
|
|
|
if (text->selection.set())
|
|
|
|
text->cursor = text->selection.end;
|
|
|
|
|
|
|
|
bv->toggleSelection();
|
|
|
|
text->clearSelection();
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
SearchResult result = nextChange(bv, text, length);
|
|
|
|
|
|
|
|
lyxerr << "Result is " << result << endl;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
bool found = true;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
// If we found the cursor inside an inset we will get back
|
|
|
|
// SR_FOUND_NOUPDATE and we don't have to do anything as the
|
|
|
|
// inset did it already.
|
|
|
|
if (result == SR_FOUND) {
|
|
|
|
bv->unlockInset(bv->theLockingInset());
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(text, BufferView::SELECT);
|
2003-03-17 16:25:00 +00:00
|
|
|
text->setSelectionRange(length);
|
2003-02-08 19:18:01 +00:00
|
|
|
bv->toggleSelection(false);
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(text, BufferView::SELECT);
|
2003-02-08 19:18:01 +00:00
|
|
|
} else if (result == SR_NOT_FOUND) {
|
|
|
|
bv->unlockInset(bv->theLockingInset());
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(text, BufferView::SELECT);
|
2003-02-08 19:18:01 +00:00
|
|
|
found = false;
|
|
|
|
}
|
|
|
|
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->fitCursor();
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
return found;
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
} // end lyxfind namespace
|