* formulabase.C: fix memory leak
+ * math_cursor.C: ^ now copies selection into new srriptinset
+
2001-07-22 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* formula.C (insetAllowed): allow insertion of label
}
-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));
}
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;
}
}
-MathUpDownInset * MathCursor::nearbyUpDownInset() const
+MathUpDownInset * MathCursor::prevUpDownInset() const
{
normalize();
MathInset * p = array().prevInset(cursor().pos_);
- if (p && p->isUpDownInset())
- return static_cast<MathUpDownInset *>(p);
- //p = array().nextInset(cursor().pos_);
- //if (p && p->isUpDownInset())
- // return static_cast<MathUpDownInset *>(p);
- return 0;
+ return (p && p->isUpDownInset()) ? static_cast<MathUpDownInset *>(p) : 0;
}