]> git.lyx.org Git - lyx.git/commitdiff
make cursor less eager to leave the formula when pressing 'up' or 'down'
authorAndré Pönitz <poenitz@gmx.net>
Thu, 15 Nov 2001 09:51:57 +0000 (09:51 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 15 Nov 2001 09:51:57 +0000 (09:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3030 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/mathed/formula.C
src/mathed/math_atom.C
src/mathed/math_atom.h
src/mathed/math_cursor.C
src/mathed/math_exintinset.C
src/mathed/math_extern.C
src/mathed/math_fracbase.C
src/mathed/math_fracbase.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_scriptinset.C
src/mathed/math_scriptinset.h

index ce8e4d5bc000fa466e073c9bf520927944d46686..a4441609b2bc5b406b0232a005a14351829c0247 100644 (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;
        }
index 8a47a3e7239766fdcfc785bd5f8b2db736f84890..bcf72881cce99c386ffa57024577587021d6f221 100644 (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();
index 543a861ecfe6ac427d7156a3418cb79aba596f6b..8713c4113b17823d2acd64df1338df8af3a98d44 100644 (file)
@@ -43,8 +43,6 @@ public:
        ///
        void reset(MathInset * p);
        ///
-       bool hasNucleus() const;
-       ///
        MathInset * nucleus() const;
        ///
        MathInset * operator->() const;
index 7526a637e971448eb4c98bd3225cc9263da3220a..792493ea596aaf11659c514428dd5caeafa2c9c5 100644 (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;
index 4fce6e180de03f38fab9f3bd7a28c2347fb0d3fd..23758c6ee7bb67f6e5bcf26c847ce3383570063f 100644 (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 << ']';
 }
 
index 4846bf146fb9e12b295135be2e18169bb5b28f0d..d6e0d6860328845172b186e6d9b609ab4980e00c 100644 (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);
index 5efcc40b26786879a94a7ee354a7c7e6e1b01133..01745ff548f1109ba83ac39247e06613bf74575b 100644 (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
 {
index 08f05017d5a9212623f6040432c8acbbbf0dddb6..035d4f7c4d1e0495262856388d0f7f8a72f997f9 100644 (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
index 37000b258379e5ce5670c1b78a4d8802cc19bc3f..320d03f269eebb8aceb032dc42d2ba0a7152c744 100644 (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;
index a6587c43988cec3cc1fd28cf3862b428febdb159..b617ed20af942f9bc29028689892bc54b0a9a1a4 100644 (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;
index 1180becf75817479e758cc4578f3c8406ab040c3..b403760e0bd81f10530dfce04a5fc752444f3366 100644 (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";
index 32424933e9ae003eb08f8e3eaa913644b9e5e49e..6ecf64f4dba71a02e0eaa755ba1762f085e86727 100644 (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;