make cursor less eager to leave the formula when pressing 'up' or 'down'

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3030 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-11-15 09:51:57 +00:00
parent cb86c2c1d0
commit ea35e1c460
12 changed files with 214 additions and 70 deletions

View File

@ -61,6 +61,7 @@ namespace {
lyxerr << "calling: " << full << "\n";
Systemcalls dummy(Systemcalls::System, full, 0);
string out = GetFileContents(outfile);
lyx::unlink(outfile);
lyxerr << "result: '" << out << "'\n";
return out;
}

View File

@ -42,10 +42,10 @@ MathAtom::MathAtom(MathAtom const & p)
void MathAtom::operator=(MathAtom const & p)
{
if (this != &p) {
done();
copy(p);
}
if (this == &p)
return;
done();
copy(p);
}
@ -85,12 +85,6 @@ MathInset * MathAtom::nucleus() const
}
bool MathAtom::hasNucleus() const
{
return nucleus_;
}
MathInset * MathAtom::operator->() const
{
return nucleus();

View File

@ -43,8 +43,6 @@ public:
///
void reset(MathInset * p);
///
bool hasNucleus() const;
///
MathInset * nucleus() const;
///
MathInset * operator->() const;

View File

@ -591,25 +591,22 @@ bool MathCursor::up(bool sel)
selHandle(sel);
if (!selection_) {
// check whether we could move into a superscript
if (hasPrevAtom()) {
MathAtom & p = prevAtom();
if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
pushRight(p);
idx() = 1;
pos() = size();
return true;
}
MathInset::idx_type i = 0;
MathInset::pos_type p = 0;
// check whether we could move into the inset
if (hasPrevAtom() && prevAtom()->idxLastUp(i, p)) {
pushRight(prevAtom());
idx() = i;
pos() = p;
return true;
}
if (hasNextAtom()) {
MathAtom & n = nextAtom();
if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
pushLeft(n);
idx() = 1;
pos() = 0;
return true;
}
if (hasNextAtom() && nextAtom()->idxFirstUp(i, p)) {
pushLeft(nextAtom());
idx() = i;
pos() = p;
return true;
}
}
@ -624,25 +621,22 @@ bool MathCursor::down(bool sel)
selHandle(sel);
if (!selection_) {
// check whether we could move into a subscript
if (hasPrevAtom()) {
MathAtom & p = prevAtom();
if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
pushRight(p);
idx() = 0;
pos() = size();
return true;
}
MathInset::idx_type i = 0;
MathInset::pos_type p = 0;
// check whether we could move into the inset
if (hasPrevAtom() && prevAtom()->idxLastDown(i, p)) {
pushRight(prevAtom());
idx() = i;
pos() = p;
return true;
}
if (hasNextAtom()) {
MathAtom & n = nextAtom();
if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
pushLeft(n);
idx() = 0;
pos() = 0;
return true;
}
if (hasNextAtom() && nextAtom()->idxFirstDown(i, p)) {
pushLeft(nextAtom());
idx() = i;
pos() = p;
return true;
}
}
@ -1212,6 +1206,8 @@ bool MathCursor::goDown()
return true;
}
// does the inset know
// if not, apply brute force.
int x0;
int y0;

View File

@ -6,7 +6,7 @@
MathExIntInset::MathExIntInset(string const & name)
: MathNestInset(2), symbol_(name)
: MathNestInset(2), symbol_(name), scripts_(new MathScriptInset)
{}
@ -36,7 +36,8 @@ void MathExIntInset::symbol(string const & symbol)
bool MathExIntInset::hasScripts() const
{
return scripts_.hasNucleus();
// take empty upper bound as "no scripts"
return !scripts_->asScriptInset()->up().data_.empty();
}
@ -45,7 +46,7 @@ void MathExIntInset::normalize(NormalStream & os) const
{
os << '[' << symbol_.c_str() << ' ' << cell(0) << ' ' << cell(1);
if (hasScripts())
os << scripts_.nucleus();
os << ' ' << scripts_.nucleus();
os << ']';
}

View File

@ -271,13 +271,24 @@ void extractFunctions(MathArray & ar)
return;
lyxerr << "\nFunctions from: " << ar << "\n";
for (MathArray::size_type i = 0; i < ar.size() - 1; ++i) {
for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) {
MathArray::iterator it = ar.begin() + i;
// is this a function name?
// is this a well known function name?
MathFuncInset * func = (*it)->asFuncInset();
if (!func)
string name;
if (func)
name = func->name();
else {
// is this a user defined function?
// guess so, if this is a "string" and it is followed by
// a DelimInset
//name = extractString((*it)->nucleus());
//if (name.size() && it + 1
//if ((*it
// FIXME
continue;
}
// do we have an exponent?
// simply skippping the postion does the right thing:
@ -293,7 +304,7 @@ void extractFunctions(MathArray & ar)
}
// create a proper inset as replacement
MathExFuncInset * p = new MathExFuncInset(func->name());
MathExFuncInset * p = new MathExFuncInset(name);
// jt points to the "argument". Get hold of this.
MathArray::iterator st = extractArgument(p->cell(0), jt, ar.end());
@ -339,7 +350,7 @@ void extractIntegrals(MathArray & ar)
return;
lyxerr << "\nIntegrals from: " << ar << "\n";
for (MathArray::size_type i = 0; i < ar.size() - 1; ++i) {
for (MathArray::size_type i = 0; i + 1< ar.size(); ++i) {
MathArray::iterator it = ar.begin() + i;
// is this a integral name?
@ -409,7 +420,7 @@ void extractSums(MathArray & ar)
return;
lyxerr << "\nSums from: " << ar << "\n";
for (MathArray::size_type i = 0; i < ar.size() - 1; ++i) {
for (MathArray::size_type i = 0; i + 1< ar.size(); ++i) {
MathArray::iterator it = ar.begin() + i;
// is this a sum name?
@ -439,7 +450,6 @@ void extractSums(MathArray & ar)
} else {
// use everything as summation index, don't use scripts.
p->cell(1) = ar;
p->scripts().reset(0);
}
}
}
@ -483,7 +493,7 @@ bool diffFracTest(MathInset * p)
void extractDiff(MathArray & ar)
{
lyxerr << "\nDiffs from: " << ar << "\n";
for (MathArray::size_type i = 0; i < ar.size() - 1; ++i) {
for (MathArray::size_type i = 0; i < ar.size(); ++i) {
MathArray::iterator it = ar.begin() + i;
// is this a "differential fraction"?
@ -499,15 +509,39 @@ void extractDiff(MathArray & ar)
// create a proper diff inset
MathDiffInset * p = new MathDiffInset;
// collect function
// collect function, let jt point behind last used item
MathArray::iterator jt = it + 1;
if (f->cell(0).size() > 1)
p->cell(0) = MathArray(f->cell(0).begin() + 1, f->cell(0).end());
else
jt = extractArgument(p->cell(0), jt, ar.end());
int n = 1;
MathArray & numer = f->cell(0);
if (numer.size() > 1 && numer.at(1)->asScriptInset()) {
// this is something like d^n f(x) / d... or d^n / d...
n = 1; // FIXME
if (numer.size() > 2)
p->cell(0) = MathArray(numer.begin() + 2, numer.end());
else
jt = extractArgument(p->cell(0), jt, ar.end());
} else {
// simply d f(x) / d... or d/d...
if (numer.size() > 1)
p->cell(0) = MathArray(numer.begin() + 1, numer.end());
else
jt = extractArgument(p->cell(0), jt, ar.end());
}
// collect denominator
MathArray & denom = f->cell(1);
for (MathArray::iterator dt = denom.begin(); dt + 1 != denom.end(); ) {
if (!diffItemTest((*dt).nucleus())) {
lyxerr << "extractDiff: should not happen 2\n";
return;
}
MathArray diff;
dt = extractArgument(diff, dt + 1, denom.end());
p->addDer(diff);
// safeguard
if (dt == denom.end())
break;
}
// cleanup
ar.erase(it + 1, jt);

View File

@ -25,6 +25,38 @@ bool MathFracbaseInset::idxLeft(MathInset::idx_type &,
}
bool MathFracbaseInset::idxFirstUp(idx_type & idx, pos_type & pos) const
{
idx = 0;
pos = 0;
return true;
}
bool MathFracbaseInset::idxFirstDown(idx_type & idx, pos_type & pos) const
{
idx = 1;
pos = 0;
return true;
}
bool MathFracbaseInset::idxLastUp(idx_type & idx, pos_type & pos) const
{
idx = 0;
pos = cell(0).size();
return true;
}
bool MathFracbaseInset::idxLastDown(idx_type & idx, pos_type & pos) const
{
idx = 1;
pos = cell(1).size();
return true;
}
bool MathFracbaseInset::idxUp(MathInset::idx_type & idx,
MathInset::pos_type & pos) const
{

View File

@ -13,13 +13,21 @@ public:
///
MathFracbaseInset();
///
bool idxUp(MathInset::idx_type &, MathInset::pos_type &) const;
bool idxUp(idx_type &, pos_type &) const;
///
bool idxDown(MathInset::idx_type &, MathInset::pos_type &) const;
bool idxDown(idx_type &, pos_type &) const;
///
bool idxLeft(MathInset::idx_type &, MathInset::pos_type &) const;
bool idxLeft(idx_type &, pos_type &) const;
///
bool idxRight(MathInset::idx_type &, MathInset::pos_type &) const;
bool idxRight(idx_type &, pos_type &) const;
///
bool idxFirstUp(idx_type &, pos_type &) const;
///
bool idxFirstDown(idx_type &, pos_type &) const;
///
bool idxLastUp(idx_type &, pos_type &) const;
///
bool idxLastDown(idx_type &, pos_type &) const;
};
#endif

View File

@ -132,12 +132,36 @@ bool MathInset::idxFirst(idx_type &, pos_type &) const
}
bool MathInset::idxFirstUp(idx_type &, pos_type &) const
{
return false;
}
bool MathInset::idxFirstDown(idx_type &, pos_type &) const
{
return false;
}
bool MathInset::idxLast(idx_type &, pos_type &) const
{
return false;
}
bool MathInset::idxLastUp(idx_type &, pos_type &) const
{
return false;
}
bool MathInset::idxLastDown(idx_type &, pos_type &) const
{
return false;
}
bool MathInset::idxHome(idx_type &, pos_type &) const
{
return false;

View File

@ -119,8 +119,16 @@ public:
/// Target pos when we enter the inset from the left by pressing "Right"
virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
/// Target pos when we enter the inset from the left by pressing "Up"
virtual bool idxFirstUp(idx_type & idx, pos_type & pos) const;
/// Target pos when we enter the inset from the left by pressing "Down"
virtual bool idxFirstDown(idx_type & idx, pos_type & pos) const;
/// Target pos when we enter the inset from the right by pressing "Left"
virtual bool idxLast(idx_type & idx, pos_type & pos) const;
/// Target pos when we enter the inset from the right by pressing "Up"
virtual bool idxLastUp(idx_type & idx, pos_type & pos) const;
/// Target pos when we enter the inset from the right by pressing "Down"
virtual bool idxLastDown(idx_type & idx, pos_type & pos) const;
/// Where should we go if we press home?
virtual bool idxHome(idx_type & idx, pos_type & pos) const;

View File

@ -272,6 +272,46 @@ bool MathScriptInset::idxLeft(MathInset::idx_type &,
}
bool MathScriptInset::idxFirstUp(idx_type & idx, pos_type & pos) const
{
if (!hasUp())
return false;
idx = 1;
pos = 0;
return true;
}
bool MathScriptInset::idxFirstDown(idx_type & idx, pos_type & pos) const
{
if (!hasDown())
return false;
idx = 0;
pos = 0;
return true;
}
bool MathScriptInset::idxLastUp(idx_type & idx, pos_type & pos) const
{
if (!hasUp())
return false;
idx = 1;
pos = up().data_.size();
return true;
}
bool MathScriptInset::idxLastDown(idx_type & idx, pos_type & pos) const
{
if (!hasDown())
return false;
idx = 0;
pos = down().data_.size();
return true;
}
void MathScriptInset::write(WriteStream & os) const
{
//lyxerr << "unexpected call to MathScriptInset::write()\n";

View File

@ -41,9 +41,17 @@ public:
int width(MathInset const * nuc) const;
///
bool idxLeft(MathInset::idx_type &, MathInset::pos_type &) const;
bool idxLeft(idx_type &, pos_type &) const;
///
bool idxRight(MathInset::idx_type &, MathInset::pos_type &) const;
bool idxRight(idx_type &, pos_type &) const;
///
bool idxFirstUp(idx_type &, pos_type &) const;
///
bool idxFirstDown(idx_type &, pos_type &) const;
///
bool idxLastUp(idx_type &, pos_type &) const;
///
bool idxLastDown(idx_type &, pos_type &) const;
///
MathScriptInset const * asScriptInset() const;