Backported fixes to s+r to 1.2.x. This gives a great speed improvement

to the whole thing and fixes some small bugs in it.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH-1_2_X@4793 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2002-07-26 10:19:13 +00:00
parent f96ceeea87
commit 9e929e3381
15 changed files with 280 additions and 178 deletions

View File

@ -1,3 +1,10 @@
2002-07-26 Juergen Vigna <jug@sad.it>
* lyxfunc.C (dispatch):change LyXFind function call.
* lyxfind.C (various): Don't lock insets while searching only
when we found a string. This speed ups the whole stuff a lot
2002-07-23 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* paragraph_pimpl.C (simpleTeXSpecialChars): close fonts before

View File

@ -1,3 +1,9 @@
2002-07-26 Juergen Vigna <jug@sad.it>
* ControlThesaurus.C (replace): ditto.
* ControlSearch.C (find): adaptions to changes in lyxfind.C
2002-07-15 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* biblio.C (parseBibTeX): use ascii_lowercase instead of lowercase

View File

@ -47,8 +47,9 @@ ControlSearch::ControlSearch(LyXView & lv, Dialogs & d)
void ControlSearch::find(string const & search,
bool casesensitive, bool matchword, bool forward) const
{
bool const found = LyXFind(lv_.view(), search,
forward, false, casesensitive, matchword);
bool const found = lyxfind::LyXFind(lv_.view(), search,
forward, casesensitive,
matchword);
if (!found)
setMinibuffer(&lv_, _("String not found!"));
@ -62,9 +63,10 @@ void ControlSearch::replace(string const & search, string const & replace,
// move on to the next instance once the present instance has been
// changed
bool const once = !all;
int const replace_count = LyXReplace(lv_.view(),
search, replace, true, casesensitive,
matchword, all, once);
int const replace_count =
lyxfind::LyXReplace(lv_.view(),
search, replace, true, casesensitive,
matchword, all, once);
if (replace_count == 0) {
setMinibuffer(&lv_, _("String not found!"));

View File

@ -47,8 +47,9 @@ void ControlThesaurus::replace(string const & newstr)
* on a particular charpos in a paragraph that is broken on
* deletion/change !
*/
int const replace_count = LyXReplace(lv_.view(), oldstr_, newstr,
true, true, true, false, true);
int const replace_count =
lyxfind::LyXReplace(lv_.view(), oldstr_, newstr,
true, true, true, false, true);
oldstr_ = newstr;

View File

@ -1,3 +1,11 @@
2002-07-26 Juergen Vigna <jug@sad.it>
* insettabular.C: ditto
* insettext.C: ditto
* insetcollapsable.C: adaptions to changes in lyxfind.C
2002-07-23 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* insetminipage.h (noFontChange):

View File

@ -655,7 +655,8 @@ bool InsetCollapsable::searchForward(BufferView * bv, string const & str,
bool found = inset.searchForward(bv, str, cs, mw);
if (first_after_edit && !found)
close(bv);
first_after_edit = false;
else if (!found)
first_after_edit = false;
return found;
}
@ -666,7 +667,8 @@ bool InsetCollapsable::searchBackward(BufferView * bv, string const & str,
bool found = inset.searchBackward(bv, str, cs, mw);
if (first_after_edit && !found)
close(bv);
first_after_edit = false;
else if (!found)
first_after_edit = false;
return found;
}

View File

@ -146,7 +146,7 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
clearSelection();
need_update = INIT;
in_update = false;
in_reset_pos = false;
in_reset_pos = 0;
inset_x = 0;
inset_y = 0;
}
@ -166,7 +166,7 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
clearSelection();
need_update = INIT;
in_update = false;
in_reset_pos = false;
in_reset_pos = 0;
inset_x = 0;
inset_y = 0;
}
@ -610,6 +610,7 @@ void InsetTabular::insetUnlock(BufferView * bv)
the_locking_inset = 0;
}
hideInsetCursor(bv);
actcell = 0;
oldcell = -1;
locked = false;
if (scroll(false) || hasSelection()) {
@ -633,15 +634,10 @@ void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
what = FULL;
if (need_update < what) // only set this if it has greater update
need_update = what;
#if 0 // maybe this should not be done!
if ((what == INIT) && hasSelection()) {
clearSelection();
}
#endif
// Dirty Cast! (Lgb)
if (need_update != NONE) {
bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
if (locked) // && (what != NONE))
if (locked)
resetPos(bv);
}
}
@ -1541,7 +1537,7 @@ void InsetTabular::resetPos(BufferView * bv) const
#warning This should be fixed in the right manner (20011128 Jug)
#endif
// fast hack to fix infinite repaintings!
if (in_reset_pos)
if (in_reset_pos > 10)
return;
int cell = 0;
@ -1562,7 +1558,7 @@ void InsetTabular::resetPos(BufferView * bv) const
return;
}
// we need this only from here on!!!
in_reset_pos = true;
++in_reset_pos;
static int const offset = ADD_TO_TABULAR_WIDTH + 2;
int new_x = getCellXPos(actcell);
int old_x = cursor_.x();
@ -1613,7 +1609,7 @@ void InsetTabular::resetPos(BufferView * bv) const
bv->owner()->getDialogs()->updateTabular(inset);
oldcell = actcell;
}
in_reset_pos = false;
in_reset_pos = 0;
}
@ -2753,56 +2749,53 @@ void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
bool InsetTabular::searchForward(BufferView * bv, string const & str,
bool cs, bool mw)
{
nodraw(true);
if (the_locking_inset) {
if (the_locking_inset->searchForward(bv, str, cs, mw)) {
nodraw(false);
updateLocal(bv, CELL, false);
return true;
}
if (tabular->IsLastCell(actcell)) {
nodraw(false);
bv->unlockInset(const_cast<InsetTabular *>(this));
if (tabular->IsLastCell(actcell))
return false;
}
++actcell;
}
// otherwise we have to lock the next inset and search there
UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
inset->edit(bv);
bool const ret = searchForward(bv, str, cs, mw);
nodraw(false);
updateLocal(bv, CELL, false);
return ret;
InsetText * inset = tabular->GetCellInset(actcell);
if (inset->searchForward(bv, str, cs, mw)) {
updateLocal(bv, FULL, false);
return true;
}
while (!tabular->IsLastCell(actcell)) {
++actcell;
inset = tabular->GetCellInset(actcell);
if (inset->searchForward(bv, str, cs, mw)) {
updateLocal(bv, FULL, false);
return true;
}
}
return false;
}
bool InsetTabular::searchBackward(BufferView * bv, string const & str,
bool cs, bool mw)
{
nodraw(true);
if (the_locking_inset) {
if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
nodraw(false);
updateLocal(bv, CELL, false);
return true;
}
if (!actcell) { // we are already in the first cell
nodraw(false);
bv->unlockInset(const_cast<InsetTabular *>(this));
return false;
}
--actcell;
}
// otherwise we have to lock the next inset and search there
UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
inset->edit(bv, false);
bool const ret = searchBackward(bv, str, cs, mw);
nodraw(false);
updateLocal(bv, CELL, false);
return ret;
if (!locked)
actcell = tabular->GetNumberOfCells();
while (actcell) {
--actcell;
InsetText * inset = tabular->GetCellInset(actcell);
if (inset->searchBackward(bv, str, cs, mw)) {
updateLocal(bv, CELL, false);
return true;
}
}
return false;
}

View File

@ -357,6 +357,6 @@ private:
///
bool in_update;
///
mutable bool in_reset_pos;
mutable int in_reset_pos;
};
#endif

View File

@ -1218,10 +1218,20 @@ InsetText::localDispatch(BufferView * bv,
}
break;
case FINISHED_DOWN:
if ((result = moveDown(bv)) >= FINISHED) {
{
LyXText *lt = getLyXText(bv);
if (lt->cursor.irow()->next()) {
lt->setCursorFromCoordinates(
bv, lt->cursor.ix() + inset_x,
lt->cursor.iy() -
lt->cursor.irow()->baseline() +
lt->cursor.irow()->height() + 1);
lt->cursor.x_fix(lt->cursor.x());
updateLocal(bv, CURSOR, false);
} else {
bv->unlockInset(this);
}
}
break;
default:
result = DISPATCHED;
@ -2690,53 +2700,66 @@ void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
bool InsetText::searchForward(BufferView * bv, string const & str,
bool cs, bool mw)
{
bool clear = false;
if (!lt) {
lt = getLyXText(bv);
clear = true;
}
if (the_locking_inset) {
if (the_locking_inset->searchForward(bv, str, cs, mw))
return true;
bool clear = false;
if (!lt) {
lt = getLyXText(bv);
clear = true;
}
Paragraph * lpar = lt->cursor.par();
pos_type pos = lt->cursor.pos();
if (pos < lpar->size() - 1)
++pos;
else {
pos = 0;
lpar = lpar->next();
}
if (!lpar) {
if (clear)
lt = 0;
// we have to unlock ourself in this function by default!
bv->unlockInset(const_cast<InsetText *>(this));
return false;
}
lt->setCursor(bv, lpar, pos);
if (clear)
lt = 0;
lt->cursorRight(bv, true);
}
if (LyXFind(bv, str, true, true, cs , mw)) {
return true;
lyxfind::SearchResult result =
lyxfind::LyXFind(bv, lt, str, true, cs, mw);
if (result == lyxfind::SR_FOUND) {
LyXCursor cur = lt->cursor;
bv->unlockInset(bv->theLockingInset());
if (bv->lockInset(this))
locked = true;
lt->cursor = cur;
lt->setSelectionOverString(bv, str);
updateLocal(bv, SELECTION, false);
}
// we have to unlock ourself in this function by default!
bv->unlockInset(const_cast<InsetText *>(this));
return false;
if (clear)
lt = 0;
return (result != lyxfind::SR_NOT_FOUND);
}
bool InsetText::searchBackward(BufferView * bv, string const & str,
bool cs, bool mw)
{
if (the_locking_inset)
if (the_locking_inset) {
if (the_locking_inset->searchBackward(bv, str, cs, mw))
return true;
if (LyXFind(bv, str, false, true, cs, mw)) {
return true;
}
// we have to unlock ourself in this function by default!
bv->unlockInset(const_cast<InsetText *>(this));
return false;
bool clear = false;
if (!lt) {
lt = getLyXText(bv);
clear = true;
}
if (!locked) {
Paragraph * p = par;
while (p->next())
p = p->next();
lt->setCursor(bv, p, p->size());
}
lyxfind::SearchResult result =
lyxfind::LyXFind(bv, lt, str, false, cs, mw);
if (result == lyxfind::SR_FOUND) {
LyXCursor cur = lt->cursor;
bv->unlockInset(bv->theLockingInset());
if (bv->lockInset(this))
locked = true;
lt->cursor = cur;
lt->setSelectionOverString(bv, str);
updateLocal(bv, SELECTION, false);
}
if (clear)
lt = 0;
return (result != lyxfind::SR_NOT_FOUND);
}

View File

@ -14,22 +14,11 @@
#include "buffer.h"
#include "debug.h"
#include "gettext.h"
#include "insets/insettext.h"
using lyx::pos_type;
///
// locally used enum
///
enum SearchResult {
//
SR_NOT_FOUND = 0,
//
SR_FOUND,
//
SR_FOUND_NOUPDATE
};
namespace lyxfind {
/// returns true if the specified string is at the specified position
bool IsStringInText(Paragraph * par, pos_type pos,
@ -43,7 +32,6 @@ SearchResult SearchForward(BufferView *, LyXText * text, string const & str,
SearchResult SearchBackward(BufferView *, LyXText * text, string const & str,
bool const & = true, bool const & = false);
int LyXReplace(BufferView * bv,
string const & searchstr, string const & replacestr,
bool forward, bool casesens, bool matchwrd, bool replaceall,
@ -62,17 +50,14 @@ int LyXReplace(BufferView * bv,
return 0;
}
LyXText * text = bv->getLyXText();
// now we can start searching for the first
// start at top if replaceall
LyXText * text = bv->getLyXText();
bool fw = forward;
if (replaceall) {
text->clearSelection();
if (text->inset_owner) {
bv->unlockInset(bv->theLockingInset());
text = bv->text;
}
bv->unlockInset(bv->theLockingInset());
text = bv->text;
text->cursorTop(bv);
// override search direction because we search top to bottom
fw = true;
@ -90,7 +75,7 @@ int LyXReplace(BufferView * bv,
str2 = lowercase(text->selectionAsString(bv->buffer(), false));
}
if (str1 != str2) {
if (!LyXFind(bv, searchstr, fw, false, casesens, matchwrd) ||
if (!LyXFind(bv, searchstr, fw, casesens, matchwrd) ||
!replaceall)
{
return 0;
@ -100,15 +85,23 @@ int LyXReplace(BufferView * bv,
bool found = false;
int replace_count = 0;
do {
bv->hideCursor();
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
bv->toggleSelection(false);
bv->getLyXText()->replaceSelectionWithString(bv, replacestr);
bv->getLyXText()->setSelectionOverString(bv, replacestr);
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
++replace_count;
text = bv->getLyXText();
// 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())))
{
bv->hideCursor();
bv->update(text, BufferView::SELECT|BufferView::FITCUR);
bv->toggleSelection(false);
text->replaceSelectionWithString(bv, replacestr);
text->setSelectionOverString(bv, replacestr);
bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
++replace_count;
}
if (!once)
found = LyXFind(bv, searchstr, fw, false, casesens, matchwrd);
found = LyXFind(bv, searchstr, fw, casesens, matchwrd);
} while (!once && replaceall && found);
if (bv->focus())
@ -119,75 +112,83 @@ int LyXReplace(BufferView * bv,
bool LyXFind(BufferView * bv,
string const & searchstr, bool forward,
bool frominset, bool casesens, bool matchwrd)
bool casesens, bool matchwrd)
{
if (!bv->available() || searchstr.empty())
return false;
LyXText * text = bv->getLyXText();
bv->hideCursor();
bv->update(text, BufferView::SELECT|BufferView::FITCUR);
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
if (bv->theLockingInset()) {
bool found = forward ?
bv->theLockingInset()->searchForward(bv, searchstr, casesens, matchwrd) :
bv->theLockingInset()->searchBackward(bv, searchstr, casesens, matchwrd);
// 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;
// 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) {
bv->text->cursorRight(bv, true);
}
}
// 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 = forward ?
text->selection.end : text->selection.start;
SearchResult result = SR_NOT_FOUND;
if (!frominset && bv->theLockingInset()) {
bool found = forward ?
bv->theLockingInset()->searchForward(bv, searchstr, casesens, matchwrd) :
bv->theLockingInset()->searchBackward(bv, searchstr, casesens, matchwrd);
if (found)
result = SR_FOUND_NOUPDATE;
else {
text = bv->getLyXText();
Paragraph * par = text->cursor.par();
pos_type pos = text->cursor.pos();
if (forward) {
if (pos < par->size() - 1)
++pos;
else {
pos = 0;
par = par->next();
}
if (par)
text->setCursor(bv, par, pos);
}
if (par) {
result = forward ?
SearchForward(bv, text, searchstr, casesens, matchwrd) :
SearchBackward(bv, text, searchstr, casesens, matchwrd);
}
}
} else {
result = forward ?
SearchForward(bv, text, searchstr, casesens, matchwrd) :
SearchBackward(bv, text, searchstr, casesens, matchwrd);
}
bv->toggleSelection();
text->clearSelection();
SearchResult result = forward ?
SearchForward(bv, text, searchstr, casesens, matchwrd) :
SearchBackward(bv, text, searchstr, casesens, matchwrd);
bool found = true;
// 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) {
// the actual text pointer could have changed!
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
bv->toggleSelection();
bv->getLyXText()->clearSelection();
bv->getLyXText()->setSelectionOverString(bv, searchstr);
bv->unlockInset(bv->theLockingInset());
bv->update(text, BufferView::SELECT|BufferView::FITCUR);
text->setSelectionOverString(bv, searchstr);
bv->toggleSelection(false);
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
bv->update(text, BufferView::SELECT|BufferView::FITCUR);
} else if (result == SR_NOT_FOUND) {
bv->toggleSelection();
bv->getLyXText()->clearSelection();
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
bv->unlockInset(bv->theLockingInset());
bv->update(text, BufferView::SELECT|BufferView::FITCUR);
found = false;
}
if (bv->focus())
if (result != SR_FOUND_NOUPDATE && bv->focus())
bv->showCursor();
return found;
}
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;
}
// returns true if the specified string is at the specified position
bool IsStringInText(Paragraph * par, pos_type pos,
@ -235,12 +236,13 @@ SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str,
(inset = (UpdatableInset *)par->getInset(pos)) &&
(inset->isTextInset()))
{
#if 0
// lock the inset!
text->setCursor(bv, par, pos);
inset->edit(bv);
#endif
if (inset->searchForward(bv, str, cs, mw))
return SR_FOUND_NOUPDATE;
text = bv->getLyXText();
}
++pos;
@ -292,12 +294,13 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text,
(inset = (UpdatableInset *)par->getInset(pos)) &&
(inset->isTextInset()))
{
#if 0
// lock the inset!
text->setCursor(bv, par, pos);
inset->edit(bv, false);
#endif
if (inset->searchBackward(bv, str, cs, mw))
return SR_FOUND_NOUPDATE;
text = bv->getLyXText();
}
} while (par && !IsStringInText(par, pos, str, cs, mw));
@ -310,3 +313,5 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text,
return SR_NOT_FOUND;
}
}
} // end lyxfind namespace

View File

@ -11,13 +11,43 @@
class BufferView;
int LyXReplace(BufferView * bv, string const &, string const &,
namespace lyxfind {
enum SearchResult {
//
SR_NOT_FOUND = 0,
//
SR_FOUND,
//
SR_FOUND_NOUPDATE
};
int LyXReplace(BufferView * bv,
string const &, string const &,
bool, bool = true, bool = false,
bool = false, bool = false);
/**
* This function is called as a general interface to find some
* text from the actual cursor position in whatever direction
* we want to go. This does also update the screen.
*/
bool LyXFind(BufferView *,
string const & searchstr, bool forward,
bool frominset = false, bool casesens = true,
bool matchwrd = false);
bool casesens = true, bool matchwrd = false);
/**
* This function does search from the cursor position inside the
* passed LyXText parameter and regards this LyXText as the root
* LyXText. It will NOT update any screen stuff. It will however
* set the cursor to the new position inside LyXText, before
* returning to the calling function.
*/
SearchResult LyXFind(BufferView *, LyXText * text,
string const & searchstr, bool forward,
bool casesens = true, bool matchwrd = false);
} // end namespace LyXFind
#endif

View File

@ -1047,7 +1047,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
}
bool fw = (action == LFUN_WORDFINDBACKWARD);
if (!searched_string.empty()) {
LyXFind(owner->view(), searched_string, fw);
lyxfind::LyXFind(owner->view(), searched_string, fw);
}
// owner->view()->showCursor();
}

View File

@ -1,3 +1,9 @@
2002-07-26 Juergen Vigna <jug@sad.it>
* formulabase.h: added support for fitInsetCursor().
* formulabase.C: adaptions to changes in lyxfind.C
2002-07-22 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* math_support.C (mathed_draw_deco): fix rounding bug for rotated

View File

@ -198,8 +198,9 @@ void InsetFormulaBase::insetUnlock(BufferView * bv)
}
void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
void InsetFormulaBase::getCursorPos(BufferView * bv, int & x, int & y) const
{
metrics(bv);
mathcursor->getPos(x, y);
//x -= xo_;
y -= yo_;
@ -258,6 +259,20 @@ void InsetFormulaBase::hideInsetCursor(BufferView * bv)
}
void InsetFormulaBase::fitInsetCursor(BufferView * bv) const
{
if (!mathcursor)
return;
int const asc = lyxfont::maxAscent(font_);
int const desc = lyxfont::maxDescent(font_);
int x, y;
getCursorPos(bv, x, y);
bv->fitLockedInsetCursor(x, y, asc, desc);
}
void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
{
if (mathcursor)
@ -274,6 +289,8 @@ vector<string> const InsetFormulaBase::getLabelList() const
void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
{
metrics(bv);
if (mathcursor)
bv->fitCursor();
bv->updateInset(this, dirty);
}
@ -845,24 +862,24 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
if (it.cell().matchpart(ar, it.position().pos_)) {
bv->unlockInset(bv->theLockingInset());
if (!bv->lockInset(this)) {
lyxerr << "Cannot lock inset" << endl;
return false;
}
delete mathcursor;
mathcursor = new MathCursor(this, true);
metrics(bv);
mathcursor->setSelection(it.cursor(), ar.size());
current = it;
it.jump(ar.size());
// I guess some of the following can go
bv->toggleSelection(true);
hideInsetCursor(bv);
updateLocal(bv, true);
showInsetCursor(bv);
metrics(bv);
updateLocal(bv, false);
return true;
}
}
//lyxerr << "not found!\n";
lastformula = 0;
// we have to unlock ourself in this function by default!
// don't ask me why...
bv->unlockInset(this);
return false;
}

View File

@ -74,6 +74,8 @@ public:
///
virtual void hideInsetCursor(BufferView *);
///
virtual void fitInsetCursor(BufferView *) const;
///
virtual void getCursorPos(BufferView *, int &, int &) const;
///
virtual void toggleInsetSelection(BufferView * bv);