forward search in math insets. ugly. seems to work. don't ask why.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3279 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-01-03 09:41:26 +00:00
parent 59a3a301c6
commit a3f60ae91e
9 changed files with 118 additions and 10 deletions

View File

@ -40,8 +40,10 @@
#include "math_cursor.h"
#include "math_factory.h"
#include "math_hullinset.h"
#include "math_iterator.h"
#include "math_macrotable.h"
#include "math_parser.h"
#include "math_pos.h"
#include "math_spaceinset.h"
#include "undo_funcs.h"
@ -113,6 +115,7 @@ void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
metrics(bv);
}
void InsetFormulaBase::metrics(BufferView * bv) const
{
if (bv)
@ -220,7 +223,7 @@ void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
MathMetricsInfo mi(bv, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
bv->fitLockedInsetCursor(x, y, asc, des);
//lyxerr << "showInsetCursor: x: " << x << " y: " << y << "\n";
//lyxerr << "showInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << "\n";
}
toggleInsetCursor(bv);
}
@ -717,6 +720,64 @@ int InsetFormulaBase::xhigh() const
/////////////////////////////////////////////////////////////////////
bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
bool const &, bool const &)
{
#ifdef WITH_WARNINGS
#warning pretty ugly
#endif
static InsetFormulaBase * lastformula = 0;
static MathIterator current = MathIterator(ibegin(par().nucleus()));
static MathArray ar;
static string laststr;
if (lastformula != this || laststr != str) {
//lyxerr << "reset lastformula to " << this << "\n";
lastformula = this;
laststr = str;
current = ibegin(par().nucleus());
ar.clear();
mathed_parse_cell(ar, str);
} else {
++current;
}
//lyxerr << "searching '" << str << "' in " << this << ar << endl;
for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
if (it.cell().matchpart(ar, it.position().pos_)) {
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);
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;
}
bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what,
bool const & a, bool const & b)
{
lyxerr << "searching backward not implemented in mathed" << endl;
return searchForward(bv, what, a, b);
}
/////////////////////////////////////////////////////////////////////
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
{
if (bv->available()) {

View File

@ -102,6 +102,16 @@ public:
///
BufferView * view() const { return view_; }
///
virtual bool searchForward(BufferView *, string const &,
bool const & = true, bool const & = false);
///
virtual bool searchBackward(BufferView *, string const &,
bool const & = true, bool const & = false);
///
virtual bool isTextInset() const { return true; }
private:
/// unimplemented
void operator=(const InsetFormulaBase &);

View File

@ -1449,3 +1449,10 @@ void MathCursor::stripFromLastEqualSign()
}
void MathCursor::setSelection(cursor_type const & where, size_type n)
{
selection_ = true;
Anchor_ = where;
Cursor_ = where;
cursor().pos_ += n;
}

View File

@ -235,6 +235,8 @@ public:
void dump(char const * str) const;
///
void stripFromLastEqualSign();
/// moves on
void setSelection(cursor_type const & where, size_type n);
///
friend class Selection;

View File

@ -211,10 +211,17 @@ MathArray::iterator MathArray::end()
bool MathArray::match(MathArray const & ar) const
{
if (size() != ar.size())
return size() == ar.size() && matchpart(ar, 0);
}
bool MathArray::matchpart(MathArray const & ar, pos_type pos) const
{
if (size() < ar.size() + pos)
return false;
for (const_iterator it = begin(), jt = ar.begin(); it != end(); ++it, ++jt)
if (!it->nucleus()->match(jt->nucleus()))
const_iterator it = begin() + pos;
for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
if (!jt->nucleus()->match(it->nucleus()))
return false;
return true;
}

View File

@ -108,8 +108,12 @@ public:
void dump2() const;
///
void substitute(MathMacro const &);
///
/// looks for exact match
bool match(MathArray const &) const;
/// looks for inclusion match starting at pos
bool matchpart(MathArray const &, pos_type pos) const;
/// looks for containment
const_iterator find(MathArray const &) const;
///
void replace(ReplaceData &);

View File

@ -59,6 +59,12 @@ MathXArray const & MathIterator::xcell() const
}
MathArray const & MathIterator::cell() const
{
return par()->xcell(position().idx_).data_;
}
MathInset * MathIterator::nextInset() const
{
if (position().pos_ == xcell().data_.size())
@ -132,6 +138,13 @@ void MathIterator::operator++()
}
void MathIterator::jump(int i)
{
position().pos_ += i;
lyx::Assert(position().pos_ >= 0);
lyx::Assert(position().pos_ <= cell().size());
}
bool operator==(MathIterator const & it, MathIterator const & jt)
{
@ -151,7 +164,6 @@ bool operator!=(MathIterator const & it, MathIterator const & jt)
}
MathIterator ibegin(MathInset * p)
{
return MathIterator(p);

View File

@ -18,8 +18,10 @@ public:
MathCursorPos const & operator*() const;
///
MathCursorPos const & operator->() const;
///
/// move on one step
void operator++();
/// move on several steps
void jump(int n);
/// read access to top most item
MathCursorPos const & position() const;
/// write access to top most item
@ -32,9 +34,11 @@ public:
MathInset * par();
/// helper for iend
void goEnd();
/// read access to top most item
MathArray const & cell() const;
private:
/// write access to top most item
/// read access to top most item
MathXArray const & xcell() const;
/// write access to top most item
MathInset * nextInset() const;

View File

@ -20,6 +20,7 @@ MathCursorPos::MathCursorPos(MathInset * p)
}
MathArray & MathCursorPos::cell(MathArray::idx_type idx) const
{
lyx::Assert(par_);