mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-25 17:44:59 +00:00
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:
parent
cb86c2c1d0
commit
ea35e1c460
@ -61,6 +61,7 @@ namespace {
|
|||||||
lyxerr << "calling: " << full << "\n";
|
lyxerr << "calling: " << full << "\n";
|
||||||
Systemcalls dummy(Systemcalls::System, full, 0);
|
Systemcalls dummy(Systemcalls::System, full, 0);
|
||||||
string out = GetFileContents(outfile);
|
string out = GetFileContents(outfile);
|
||||||
|
lyx::unlink(outfile);
|
||||||
lyxerr << "result: '" << out << "'\n";
|
lyxerr << "result: '" << out << "'\n";
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,10 @@ MathAtom::MathAtom(MathAtom const & p)
|
|||||||
|
|
||||||
void MathAtom::operator=(MathAtom const & p)
|
void MathAtom::operator=(MathAtom const & p)
|
||||||
{
|
{
|
||||||
if (this != &p) {
|
if (this == &p)
|
||||||
done();
|
return;
|
||||||
copy(p);
|
done();
|
||||||
}
|
copy(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -85,12 +85,6 @@ MathInset * MathAtom::nucleus() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool MathAtom::hasNucleus() const
|
|
||||||
{
|
|
||||||
return nucleus_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MathInset * MathAtom::operator->() const
|
MathInset * MathAtom::operator->() const
|
||||||
{
|
{
|
||||||
return nucleus();
|
return nucleus();
|
||||||
|
@ -43,8 +43,6 @@ public:
|
|||||||
///
|
///
|
||||||
void reset(MathInset * p);
|
void reset(MathInset * p);
|
||||||
///
|
///
|
||||||
bool hasNucleus() const;
|
|
||||||
///
|
|
||||||
MathInset * nucleus() const;
|
MathInset * nucleus() const;
|
||||||
///
|
///
|
||||||
MathInset * operator->() const;
|
MathInset * operator->() const;
|
||||||
|
@ -591,25 +591,22 @@ bool MathCursor::up(bool sel)
|
|||||||
selHandle(sel);
|
selHandle(sel);
|
||||||
|
|
||||||
if (!selection_) {
|
if (!selection_) {
|
||||||
// check whether we could move into a superscript
|
MathInset::idx_type i = 0;
|
||||||
if (hasPrevAtom()) {
|
MathInset::pos_type p = 0;
|
||||||
MathAtom & p = prevAtom();
|
|
||||||
if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
|
// check whether we could move into the inset
|
||||||
pushRight(p);
|
if (hasPrevAtom() && prevAtom()->idxLastUp(i, p)) {
|
||||||
idx() = 1;
|
pushRight(prevAtom());
|
||||||
pos() = size();
|
idx() = i;
|
||||||
return true;
|
pos() = p;
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasNextAtom()) {
|
if (hasNextAtom() && nextAtom()->idxFirstUp(i, p)) {
|
||||||
MathAtom & n = nextAtom();
|
pushLeft(nextAtom());
|
||||||
if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
|
idx() = i;
|
||||||
pushLeft(n);
|
pos() = p;
|
||||||
idx() = 1;
|
return true;
|
||||||
pos() = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -624,25 +621,22 @@ bool MathCursor::down(bool sel)
|
|||||||
selHandle(sel);
|
selHandle(sel);
|
||||||
|
|
||||||
if (!selection_) {
|
if (!selection_) {
|
||||||
// check whether we could move into a subscript
|
MathInset::idx_type i = 0;
|
||||||
if (hasPrevAtom()) {
|
MathInset::pos_type p = 0;
|
||||||
MathAtom & p = prevAtom();
|
|
||||||
if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
|
// check whether we could move into the inset
|
||||||
pushRight(p);
|
if (hasPrevAtom() && prevAtom()->idxLastDown(i, p)) {
|
||||||
idx() = 0;
|
pushRight(prevAtom());
|
||||||
pos() = size();
|
idx() = i;
|
||||||
return true;
|
pos() = p;
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasNextAtom()) {
|
if (hasNextAtom() && nextAtom()->idxFirstDown(i, p)) {
|
||||||
MathAtom & n = nextAtom();
|
pushLeft(nextAtom());
|
||||||
if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
|
idx() = i;
|
||||||
pushLeft(n);
|
pos() = p;
|
||||||
idx() = 0;
|
return true;
|
||||||
pos() = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1212,6 +1206,8 @@ bool MathCursor::goDown()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// does the inset know
|
||||||
|
|
||||||
// if not, apply brute force.
|
// if not, apply brute force.
|
||||||
int x0;
|
int x0;
|
||||||
int y0;
|
int y0;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
|
|
||||||
MathExIntInset::MathExIntInset(string const & name)
|
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
|
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);
|
os << '[' << symbol_.c_str() << ' ' << cell(0) << ' ' << cell(1);
|
||||||
if (hasScripts())
|
if (hasScripts())
|
||||||
os << scripts_.nucleus();
|
os << ' ' << scripts_.nucleus();
|
||||||
os << ']';
|
os << ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,13 +271,24 @@ void extractFunctions(MathArray & ar)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
lyxerr << "\nFunctions from: " << ar << "\n";
|
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;
|
MathArray::iterator it = ar.begin() + i;
|
||||||
|
|
||||||
// is this a function name?
|
// is this a well known function name?
|
||||||
MathFuncInset * func = (*it)->asFuncInset();
|
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;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// do we have an exponent?
|
// do we have an exponent?
|
||||||
// simply skippping the postion does the right thing:
|
// simply skippping the postion does the right thing:
|
||||||
@ -293,7 +304,7 @@ void extractFunctions(MathArray & ar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create a proper inset as replacement
|
// 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.
|
// jt points to the "argument". Get hold of this.
|
||||||
MathArray::iterator st = extractArgument(p->cell(0), jt, ar.end());
|
MathArray::iterator st = extractArgument(p->cell(0), jt, ar.end());
|
||||||
@ -339,7 +350,7 @@ void extractIntegrals(MathArray & ar)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
lyxerr << "\nIntegrals from: " << ar << "\n";
|
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;
|
MathArray::iterator it = ar.begin() + i;
|
||||||
|
|
||||||
// is this a integral name?
|
// is this a integral name?
|
||||||
@ -409,7 +420,7 @@ void extractSums(MathArray & ar)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
lyxerr << "\nSums from: " << ar << "\n";
|
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;
|
MathArray::iterator it = ar.begin() + i;
|
||||||
|
|
||||||
// is this a sum name?
|
// is this a sum name?
|
||||||
@ -439,7 +450,6 @@ void extractSums(MathArray & ar)
|
|||||||
} else {
|
} else {
|
||||||
// use everything as summation index, don't use scripts.
|
// use everything as summation index, don't use scripts.
|
||||||
p->cell(1) = ar;
|
p->cell(1) = ar;
|
||||||
p->scripts().reset(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -483,7 +493,7 @@ bool diffFracTest(MathInset * p)
|
|||||||
void extractDiff(MathArray & ar)
|
void extractDiff(MathArray & ar)
|
||||||
{
|
{
|
||||||
lyxerr << "\nDiffs from: " << ar << "\n";
|
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;
|
MathArray::iterator it = ar.begin() + i;
|
||||||
|
|
||||||
// is this a "differential fraction"?
|
// is this a "differential fraction"?
|
||||||
@ -499,15 +509,39 @@ void extractDiff(MathArray & ar)
|
|||||||
// create a proper diff inset
|
// create a proper diff inset
|
||||||
MathDiffInset * p = new MathDiffInset;
|
MathDiffInset * p = new MathDiffInset;
|
||||||
|
|
||||||
// collect function
|
// collect function, let jt point behind last used item
|
||||||
MathArray::iterator jt = it + 1;
|
MathArray::iterator jt = it + 1;
|
||||||
if (f->cell(0).size() > 1)
|
int n = 1;
|
||||||
p->cell(0) = MathArray(f->cell(0).begin() + 1, f->cell(0).end());
|
MathArray & numer = f->cell(0);
|
||||||
else
|
if (numer.size() > 1 && numer.at(1)->asScriptInset()) {
|
||||||
jt = extractArgument(p->cell(0), jt, ar.end());
|
// 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
|
// 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
|
// cleanup
|
||||||
ar.erase(it + 1, jt);
|
ar.erase(it + 1, jt);
|
||||||
|
@ -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,
|
bool MathFracbaseInset::idxUp(MathInset::idx_type & idx,
|
||||||
MathInset::pos_type & pos) const
|
MathInset::pos_type & pos) const
|
||||||
{
|
{
|
||||||
|
@ -13,13 +13,21 @@ public:
|
|||||||
///
|
///
|
||||||
MathFracbaseInset();
|
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
|
#endif
|
||||||
|
@ -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
|
bool MathInset::idxLast(idx_type &, pos_type &) const
|
||||||
{
|
{
|
||||||
return false;
|
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
|
bool MathInset::idxHome(idx_type &, pos_type &) const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -119,8 +119,16 @@ public:
|
|||||||
|
|
||||||
/// Target pos when we enter the inset from the left by pressing "Right"
|
/// Target pos when we enter the inset from the left by pressing "Right"
|
||||||
virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
|
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"
|
/// Target pos when we enter the inset from the right by pressing "Left"
|
||||||
virtual bool idxLast(idx_type & idx, pos_type & pos) const;
|
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?
|
/// Where should we go if we press home?
|
||||||
virtual bool idxHome(idx_type & idx, pos_type & pos) const;
|
virtual bool idxHome(idx_type & idx, pos_type & pos) const;
|
||||||
|
@ -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
|
void MathScriptInset::write(WriteStream & os) const
|
||||||
{
|
{
|
||||||
//lyxerr << "unexpected call to MathScriptInset::write()\n";
|
//lyxerr << "unexpected call to MathScriptInset::write()\n";
|
||||||
|
@ -41,9 +41,17 @@ public:
|
|||||||
int width(MathInset const * nuc) const;
|
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;
|
MathScriptInset const * asScriptInset() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user