From 73cd1891e848247e0fa08d2cd02e68f57e2aba38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 9 Aug 2002 08:14:18 +0000 Subject: [PATCH] up/down tweaks git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4915 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_cursor.C | 4 ++++ src/mathed/math_data.C | 7 +++---- src/mathed/math_data.h | 2 ++ src/mathed/math_scriptinset.C | 34 ++++++++++++++++++++++++++-------- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index b678a04c8a..a6d28adcb9 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -380,11 +380,15 @@ void MathCursor::niceInsert(MathAtom const & t) macroModeClose(); MathGridInset safe = grabAndEraseSelection(); plainInsert(t); + int x, y; + getPos(x, y); // enter the new inset and move the contents of the selection if possible if (t->isActive()) { posLeft(); pushLeft(nextAtom()); paste(safe); + // lets pretend we've not moved too far away... + array().setXY(x, y); } } diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C index 3b9a0da49d..8ee1a3418e 100644 --- a/src/mathed/math_data.C +++ b/src/mathed/math_data.C @@ -382,10 +382,9 @@ void MathArray::towards(int & x, int & y) const } -/* -std::ostream & operator<<(std::ostream & os, MathArray const & ar) +void MathArray::setXY(int x, int y) { - os << ar.data(); + xo_ = x; + yo_ = y; } -*/ diff --git a/src/mathed/math_data.h b/src/mathed/math_data.h index a7aabc093d..34db878f91 100644 --- a/src/mathed/math_data.h +++ b/src/mathed/math_data.h @@ -124,6 +124,8 @@ public: int xm() const { return xo_ + dim_.w / 2; } /// access to cached y coordinate of mid point of last drawing int ym() const { return yo_ + (dim_.d - dim_.a) / 2; } + /// write access to coordinate; + void setXY(int x, int y); /// returns x coordinate of given position in the array int pos2x(size_type pos) const; /// returns position of given x coordinate diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index f0023d9f66..da94d8df19 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -325,17 +325,35 @@ bool MathScriptInset::idxLeft(idx_type &, pos_type &) const bool MathScriptInset::idxUpDown(idx_type & idx, pos_type & pos, bool up, int) const { - if ((idx == 1 && up) || (idx == 0 && !up)) - return false; - - // in nuclues? - if (idx == 2) { - idx = up; - pos = 0; - } else { + if (idx == 1) { + // if we are 'up' we can't go further up + if (up) + return false; + // otherwise go to last base position idx = 2; pos = cell(2).size(); } + + else if (idx == 0) { + // if we are 'down' we can't go further down + if (!up) + return false; + idx = 2; + pos = cell(2).size(); + } + + else { + // in nucleus + // don't go up/down unless in last position + if (pos != cell(2).size()) + return false; + // don't go up/down if there is no cell. + if (!has(up)) + return false; + // otherwise move into the first position + idx = up; + pos = 0; + } return true; }