diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 4bf8501ec1..1034326f4a 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -8,6 +8,8 @@ * formulabase.C: fix memory leak + * math_cursor.C: ^ now copies selection into new srriptinset + 2001-07-22 Jean-Marc Lasgouttes * formula.C (insetAllowed): allow insertion of label diff --git a/src/mathed/array.C b/src/mathed/array.C index c73d888503..c1cee61e43 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -151,15 +151,15 @@ void MathArray::setCode(int pos, MathTextCodes t) } -void MathArray::insert(int pos, MathInset * p) +void MathArray::replace(int pos, MathInset * p) { - bf_.insert(bf_.begin() + pos, 2 + sizeof(p), LM_TC_INSET); memcpy(&bf_[pos + 1], &p, sizeof(p)); } -void MathArray::replace(int pos, MathInset * p) +void MathArray::insert(int pos, MathInset * p) { + bf_.insert(bf_.begin() + pos, 2 + sizeof(p), LM_TC_INSET); memcpy(&bf_[pos + 1], &p, sizeof(p)); } diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 27bb3006f0..6ac93ae45f 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -628,29 +628,23 @@ void MathCursor::Interpret(string const & s) lyxerr << "Interpret: '" << s << "' ('" << s.substr(0, 7) << "' " << in_word_set(s) << " \n"; - if (s[0] == '^') { - MathUpDownInset * p = nearbyUpDownInset(); + if (s[0] == '^' || s[0] == '_') { + bool const up = (s[0] == '^'); + SelCut(); + MathUpDownInset * p = prevUpDownInset(); if (!p) { - p = new MathScriptInset(true, false); + p = new MathScriptInset(up, !up); insert(p); plainLeft(); } push(p, true); - p->up(true); - cursor().idx_ = 0; - return; - } - - if (s[0] == '_') { - MathUpDownInset * p = nearbyUpDownInset(); - if (!p) { - p = new MathScriptInset(false, true); - insert(p); - plainLeft(); - } - push(p, true); - p->down(true); - cursor().idx_ = 1; + if (up) + p->up(true); + else + p->down(true); + cursor().idx_ = up ? 0 : 1; + cursor().pos_ = 0; + SelPaste(); return; } @@ -1103,16 +1097,11 @@ MathInset * MathCursor::nextInset() const } -MathUpDownInset * MathCursor::nearbyUpDownInset() const +MathUpDownInset * MathCursor::prevUpDownInset() const { normalize(); MathInset * p = array().prevInset(cursor().pos_); - if (p && p->isUpDownInset()) - return static_cast(p); - //p = array().nextInset(cursor().pos_); - //if (p && p->isUpDownInset()) - // return static_cast(p); - return 0; + return (p && p->isUpDownInset()) ? static_cast(p) : 0; } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index d0a71e46fc..c8a7e574e4 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -258,7 +258,7 @@ public: /// MathInset * prevInset() const; /// - MathUpDownInset * nearbyUpDownInset() const; + MathUpDownInset * prevUpDownInset() const; /// MathFuncInset * imacro;