MathScriptInset::MathScriptInset(MathAtom const & at, bool up)
: MathNestInset(2), cell_1_is_up_(up), limits_(0)
{
+ BOOST_ASSERT(nargs() >= 1);
cell(0).push_back(at);
}
MathArray const & MathScriptInset::down() const
{
- return nargs() == 2 ? cell(2) : cell(1);
+ if (nargs() == 3)
+ return cell(2);
+ BOOST_ASSERT(nargs() > 1);
+ return cell(1);
}
MathArray & MathScriptInset::down()
{
- return nargs() == 2 ? cell(2) : cell(1);
+ if (nargs() == 3)
+ return cell(2);
+ BOOST_ASSERT(nargs() > 1);
+ return cell(1);
}
MathArray const & MathScriptInset::up() const
{
+ BOOST_ASSERT(nargs() > 1);
return cell(1);
}
MathArray & MathScriptInset::up()
{
+ BOOST_ASSERT(nargs() > 1);
return cell(1);
}
// just nucleus so far
cells_.push_back(MathArray());
cell_1_is_up_ = up;
- } else if (nargs() == 2 && !has(up)) {
+ } else if (nargs() == 2 && !has(up)) {
if (up) {
cells_.push_back(cell(1));
cell(1).clear();
void MathScriptInset::removeScript(bool up)
{
+ lyxerr << "MathNestInset::removeScript: 1 up: " << up << endl;
if (nargs() == 2) {
+ lyxerr << "MathNestInset::removeScript: a up: " << up << endl;
if (up == cell_1_is_up_)
cells_.pop_back();
+ lyxerr << "MathNestInset::removeScript: b up: " << up << endl;
} else if (nargs() == 3) {
if (up == true) {
swap(cells_[1], cells_[2]);
} else {
cell_1_is_up_ = true;
}
+ cells_.pop_back();
}
+ lyxerr << "MathNestInset::removeScript: 2 up: " << up << endl;
}
bool MathScriptInset::hasUp() const
{
- //lyxerr << "hasUp: " << bool(idxOfScript(true)) << endl;
//lyxerr << "1up: " << bool(cell_1_is_up_) << endl;
+ //lyxerr << "hasUp: " << bool(idxOfScript(true)) << endl;
return idxOfScript(true);
}
bool MathScriptInset::hasDown() const
{
- //lyxerr << "hasDown: " << bool(idxOfScript(false)) << endl;
//lyxerr << "1up: " << bool(cell_1_is_up_) << endl;
+ //lyxerr << "hasDown: " << bool(idxOfScript(false)) << endl;
return idxOfScript(false);
}
if (nargs() == 1)
return 0;
if (nargs() == 2)
- return cell_1_is_up_ == up ? 1 : 0;
+ return (cell_1_is_up_ == up) ? 1 : 0;
if (nargs() == 3)
return up ? 1 : 2;
BOOST_ASSERT(false);
+ // Silence compiler
+ return 0;
}
}
// Are we 'up'?
- if (cur.idx() == idxOfScript(true)) {
+ if (has(up) && cur.idx() == idxOfScript(true)) {
// can't go further up
if (up)
return false;
}
// Are we 'down'?
- if (cur.idx() == idxOfScript(false)) {
+ if (has(up) && cur.idx() == idxOfScript(false)) {
// can't go further down
if (!up)
return false;
}
-void MathScriptInset::notifyCursorLeaves(idx_type idx)
+void MathScriptInset::notifyCursorLeaves(LCursor & cur)
{
- MathNestInset::notifyCursorLeaves(idx);
+ MathNestInset::notifyCursorLeaves(cur);
// remove empty scripts if possible
- if (idx == 2 && cell(2).empty()) {
- removeScript(false); // must be a subscript...
- } else if (idx == 1 && cell(1).empty()) {
- if (nargs() == 2) {
- cell_1_is_up_ = false;
- cell(1) = cell(2);
- cells_.pop_back();
- } else if (nargs() == 1) {
- cells_.pop_back();
- }
+ if (nargs() > 2 && cur.idx() == 2 && cell(2).empty()) {
+ // must be a subscript...
+ removeScript(false);
+ // sanitize cursor, even if this slice will be removed immediately
+ cur.idx() = 0;
+ cur.pos() = 0;
+ } else if (nargs() > 1 && cur.idx() == 1 && cell(1).empty()) {
+ // could be either subscript or super script
+ removeScript(cell_1_is_up_);
+ // sanitize cursor, even if this slice will be removed immediately
+ cur.idx() = 0;
+ cur.pos() = 0;
}
}