On Sun, Apr 10, 2005 at 12:32:19PM +0200, Helge Hafting wrote: > On Sun, Apr 10, 2005 at 10:52:54AM +0300, Martin Vermeer wrote: > > On Sun, Apr 10, 2005 at 12:05:29AM +0200, Andre Poenitz wrote: > > > On Sat, Apr 09, 2005 at 04:46:45PM +0200, Helge Hafting wrote: > > > > The problem is mostly the same if applying the n-root, one expect > > > > the selection to go under the root, not above it. So perhaps > > > > the n-root ought to be a little special? It'd be consistent > > > > with the square root. > > > > > > Simply swap the meaning of idx == 0 and idx == 1 in MathRootInset then. > > > Auto-insertion goes to cell 0, if that should be the part below the > > > root, this cell should have index 0. > > > > > > Andre' > > > > Makes absolute, perfect sense. Helge, this is easy to do. Just open up > > math_rootinset.C and replace all occurrences of cell(0) with cell(1), > > and vice versa. > > > > Let us know if it works... and post the patch here ;-) > > Tried it, and it had "intereesting" side effects, as expected. > > I swapped cell(0) and cell(1) everywhere. Test results: > > 1. Applying n-root over a selection improved. (Good) > 2. DVI output still matches what's on screen (no change) > 3. "edit->math->computer algebra->maxima" > results still correct. (no change) > 4. An old saved document with the fourth root of 81 > now loaded as the 81th root of four. Saving and > reloading also swaps the n-root components. (Quite bad!) > 5. Keyboard navigation is now silly - passing through > an n-root with right-arrow goes under the root first > and then into the n-part, and finally exits > the n-root and moves on through the math. (Bad!) > 6. The third root special now sticks the "3" under > the root sign. (Wrong) > > So I wonder if this was the right approach - or would a special > case in pasting be better? > > If we go with this approach, I believe I could track down issue(3). > The "write" part in math_rootinset.C was changed, and we need > a corresponding change wherever the "read" takes place. Issue(6) > is probably not that hard either, or the third root > special could be removed as suggested. > > But what to do about issue(5)? Will that require special cases > for the n-root in math navigation? Where would that be? > > I wonder if this was the right approach - or would a special > case in pasting be better? > > Helge Hafting I am afraid I must apologize for underestimating this. It required considerably more doings to get it all right. The knobs and buttons were all there, they just had to be found and put to use. This is actually C++ at its best ;-9
I do believe that we should have "read" methods in all the insets to replace the monolithic math parser. How to do that, is another question. See patch. - Martin
Index: mathed/math_rootinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_rootinset.C,v retrieving revision 1.47 diff -u -r1.47 math_rootinset.C --- mathed/math_rootinset.C 14 Feb 2005 15:28:45 -0000 1.47 +++ mathed/math_rootinset.C 10 Apr 2005 14:19:11 -0000 @@ -38,8 +38,8 @@ void MathRootInset::metrics(MetricsInfo & mi, Dimension & dim) const { MathNestInset::metrics(mi); - dim.asc = max(cell(0).ascent() + 5, cell(1).ascent()) + 2; - dim.des = max(cell(1).descent() + 5, cell(0).descent()) + 2; + dim.asc = max(cell(1).ascent() + 5, cell(0).ascent()) + 2; + dim.des = max(cell(0).descent() + 5, cell(1).descent()) + 2; dim.wid = cell(0).width() + cell(1).width() + 10; metricsMarkers(dim); dim_ = dim; @@ -48,11 +48,11 @@ void MathRootInset::draw(PainterInfo & pi, int x, int y) const { - int const w = cell(0).width(); + int const w = cell(1).width(); // the "exponent" - cell(0).draw(pi, x, y - 5 - cell(0).descent()); + cell(1).draw(pi, x, y - 5 - cell(1).descent()); // the "base" - cell(1).draw(pi, x + w + 8, y); + cell(0).draw(pi, x + w + 8, y); int const a = dim_.ascent(); int const d = dim_.descent(); int xp[5]; @@ -70,19 +70,54 @@ void MathRootInset::write(WriteStream & os) const { - os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}'; + os << "\\sqrt[" << cell(1) << "]{" << cell(0) << '}'; } void MathRootInset::normalize(NormalStream & os) const { - os << "[root " << cell(0) << ' ' << cell(1) << ']'; + os << "[root " << cell(1) << ' ' << cell(0) << ']'; +} + +//Note: we reverse the order here because of the cell order. +bool MathRootInset::idxLeft(LCursor & cur) const +{ + return idxNext(cur); +} + + +bool MathRootInset::idxRight(LCursor & cur) const +{ + return idxPrev(cur); +} + + +bool MathRootInset::idxFirst(LCursor & cur) const +{ + BOOST_ASSERT(ptr_cmp(&cur.inset(), this)); + if (nargs() == 0) + return false; + // Note! + cur.idx() = cur.lastidx(); + cur.pos() = 0; + return true; +} + + +bool MathRootInset::idxLast(LCursor & cur) const +{ + BOOST_ASSERT(ptr_cmp(&cur.inset(), this)); + if (nargs() == 0) + return false; + cur.idx() = 0; + cur.pos() = cur.lastpos(); + return true; } bool MathRootInset::idxUpDown(LCursor & cur, bool up) const { - LCursor::idx_type const target = up ? 0 : 1; + LCursor::idx_type const target = up ? 1 : 0; if (cur.idx() == target) return false; cur.idx() = target; @@ -93,17 +128,17 @@ void MathRootInset::maple(MapleStream & os) const { - os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))"; + os << '(' << cell(0) << ")^(1/(" << cell(1) <<"))"; } void MathRootInset::octave(OctaveStream & os) const { - os << "root(" << cell(1) << ',' << cell(0) << ')'; + os << "root(" << cell(0) << ',' << cell(1) << ')'; } void MathRootInset::mathmlize(MathMLStream & os) const { - os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot"); + os << MTag("mroot") << cell(0) << cell(1) << ETag("mroot"); } Index: mathed/math_rootinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_rootinset.h,v retrieving revision 1.32 diff -u -r1.32 math_rootinset.h --- mathed/math_rootinset.h 23 Nov 2004 23:04:52 -0000 1.32 +++ mathed/math_rootinset.h 10 Apr 2005 14:19:11 -0000 @@ -21,6 +21,16 @@ public: /// MathRootInset(); + + /// order of movement through the cells when pressing the left key + bool idxLeft(LCursor &) const; + /// order of movement through the cells when pressing the right key + bool idxRight(LCursor &) const; + /// target pos when we enter the inset from the left by pressing "Right" + bool idxFirst(LCursor &) const; + /// target pos when we enter the inset from the right bypressing "Left" + bool idxLast(LCursor &) const; + /// bool idxUpDown(LCursor & cur, bool up) const; /// Index: mathed/math_parser.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.C,v retrieving revision 1.312 diff -u -r1.312 math_parser.C --- mathed/math_parser.C 2 Mar 2005 14:26:12 -0000 1.312 +++ mathed/math_parser.C 10 Apr 2005 14:19:11 -0000 @@ -1025,8 +1025,8 @@ parse(ar, FLAG_OPTION, mode); if (ar.size()) { cell->push_back(MathAtom(new MathRootInset)); - cell->back().nucleus()->cell(0) = ar; - parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode); + cell->back().nucleus()->cell(1) = ar; + parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode); } else { cell->push_back(MathAtom(new MathSqrtInset)); parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode); Index: frontends/controllers/ControlMath.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlMath.C,v retrieving revision 1.29 diff -u -r1.29 ControlMath.C --- frontends/controllers/ControlMath.C 19 Jan 2005 15:03:30 -0000 1.29 +++ frontends/controllers/ControlMath.C 10 Apr 2005 14:19:11 -0000 @@ -64,6 +64,7 @@ void ControlMath::dispatchCubeRoot() const { dispatchFunc(LFUN_INSERT_MATH, "\\root"); + dispatchFunc(LFUN_UP); dispatchFunc(LFUN_SELFINSERT, "3"); dispatchFunc(LFUN_RIGHT); }
pgp02s8DmDTUj.pgp
Description: PGP signature