}
+MathAtom::MathAtom(MathInset * p, MathScriptInset * up, MathScriptInset * down)
+ : nucleus_(p), limits_(0), xo_(0), yo_(0)
+{
+ script_[0] = down;
+ script_[1] = up;
+}
+
MathAtom::MathAtom(MathAtom const & p)
{
}
+MathScriptInset * & MathAtom::up()
+{
+ return script_[1];
+}
+
+
+MathScriptInset * & MathAtom::down()
+{
+ return script_[0];
+}
+
+
int MathAtom::dy0() const
{
if (!down())
MathAtom(MathAtom const &);
///
explicit MathAtom(MathInset * p);
+ ///
+ MathAtom(MathInset * p, MathScriptInset * up, MathScriptInset * down);
///
virtual ~MathAtom();
///
MathScriptInset * up() const;
/// returns subscript
MathScriptInset * down() const;
+ /// returns superscript
+ MathScriptInset * & up();
+ /// returns subscript
+ MathScriptInset * & down();
///
MathInset * nucleus() const { return nucleus_; }
///
{
if (Cursor_.size() <= 1)
return false;
+ if (nextAtom())
+ nextAtom()->removeEmptyScripts();
Cursor_.pop_back();
- //array().at(pos())->removeEmptyScripts();
+ if (nextAtom())
+ nextAtom()->removeEmptyScripts();
return true;
}
{
if (Cursor_.size() <= 1)
return false;
+ if (nextAtom())
+ nextAtom()->removeEmptyScripts();
Cursor_.pop_back();
- //array().at(pos())->removeEmptyScripts();
+ if (nextAtom())
+ nextAtom()->removeEmptyScripts();
posRight();
return true;
}
void MathCursor::backspace()
{
if (posLeft()) {
- plainErase();
+ erase();
return;
}
return;
}
- if (pos() < size())
+ if (pos() == size())
+ return;
+
+ // delete nucleus, keep scripts if possible
+ MathAtom * p = prevAtom();
+ MathAtom * n = nextAtom();
+ if (pos() > 0) {
+ bool need_parans = (p->up() && n->up()) || (p->down() && n->down());
+ if (need_parans) {
+ // need empty block
+ insert('{', LM_TC_TEX);
+ insert('}', LM_TC_TEX);
+ p = prevAtom();
+ n = nextAtom();
+ }
+ // move indices to the left
+ if (n->up())
+ swap(p->up(), n->up());
+ if (n->down())
+ swap(p->down(), n->down());
plainErase();
+ return;
+ }
+ // pos == 0 now
+ if (n->up() || n->down()) {
+ insert('{', LM_TC_TEX);
+ insert('}', LM_TC_TEX);
+ p = prevAtom();
+ n = nextAtom();
+ swap(p->up(), n->up());
+ swap(p->down(), n->down());
+ }
+
+ plainErase();
dump("erase 2");
}
if (par()->idxUp(idx(), pos()))
return true;
+ // leave subscript to the nearest side
+ if (par()->asScriptInset() && par()->asScriptInset()->down()) {
+ if (pos() <= size() / 2)
+ popLeft();
+ else
+ popRight();
+ return true;
+ }
+
// if not, apply brute force.
int x0;
int y0;
if (par()->idxDown(idx(), pos()))
return true;
+ // leave superscript to the nearest side
+ if (par()->asScriptInset() && par()->asScriptInset()->up()) {
+ if (pos() <= size() / 2)
+ popLeft();
+ else
+ popRight();
+ return true;
+ }
+
// if not, apply brute force.
int x0;
int y0;
virtual bool isGrid() const { return false; }
/// identifies ArrayInsets
virtual bool isArray() const { return false; }
- /// identifies Charinsets
+ /// identifies CharInsets
virtual MathCharInset const * asCharInset() const { return 0; }
+ /// identifies ScriptInsets
+ virtual MathScriptInset const * asScriptInset() const { return 0; }
///
virtual bool isActive() const { return nargs() > 0; }
///
}
+MathScriptInset const * MathScriptInset::asScriptInset() const
+{
+ return this;
+}
+
void MathScriptInset::write(std::ostream & os, bool fragile) const
{
cell(0).write(os, fragile);
class MathScriptInset : public MathNestInset {
public:
///
- MathScriptInset(bool up);
+ explicit MathScriptInset(bool up);
///
MathInset * clone() const;
///
void metrics(MathStyles st) const;
///
void draw(Painter &, int x, int y) const;
+ ///
+ MathScriptInset const * asScriptInset() const;
+ ///
+ bool up() const { return up_; }
+ ///
+ bool down() const { return !up_; }
private:
///
bool up_;