#include "formulabase.h"
#include "math_cursor.h"
#include "math_arrayinset.h"
+#include "math_bigopinset.h"
#include "math_symbolinset.h"
#include "math_decorationinset.h"
#include "math_deliminset.h"
#include "math_dotsinset.h"
#include "math_fracinset.h"
#include "math_funcinset.h"
+#include "math_funcliminset.h"
#include "math_gridinset.h"
#include "math_macro.h"
#include "math_macroarg.h"
}
-void MathCursor::seldump(char const *) const
+void MathCursor::seldump(char const * str) const
{
//lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
//dump(" Pos");
return;
- //lyxerr << "\n\n\\n=================vvvvvvvvvvvvv======================= "
- // << str << "\ntheSelection: " << theSelection;
- //for (unsigned int i = 0; i < Cursor_.size(); ++i)
- // lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
+ lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
+ << str << "\ntheSelection: " << selection_
+ << " '" << theSelection.glue() << "'\n";
+ for (unsigned int i = 0; i < Cursor_.size(); ++i)
+ lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
+ lyxerr << "\n";
+ for (unsigned int i = 0; i < Anchor_.size(); ++i)
+ lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
//lyxerr << "\ncursor.pos_: " << cursor().pos_;
//lyxerr << "\nanchor.pos_: " << anchor().pos_;
- //lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
+ lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
}
-bool MathCursor::isInside(MathInset * p) const
+bool MathCursor::isInside(MathInset const * p) const
{
for (unsigned i = 0; i < Cursor_.size(); ++i)
if (parInset(i) == p)
{
if (!p)
return false;
+
if (!(p->isActive() || (useupdown && p->isScriptInset())))
return false;
}
-bool MathCursor::plainLeft()
+void MathCursor::plainLeft()
{
- return array().prev(cursor().pos_);
+ --cursor().pos_;
+}
+
+
+void MathCursor::plainRight()
+{
+ ++cursor().pos_;
}
push(p, false);
return true;
}
- if (plainLeft())
+ if (cursor().pos_) {
+ plainLeft();
return true;
+ }
if (cursor().par_->idxLeft(cursor().idx_, cursor().pos_))
return true;
if (pop())
}
-void MathCursor::plainRight()
-{
- ++cursor().pos_;
-}
-
-
bool MathCursor::right(bool sel)
{
dump("Right 1");
push(p, true);
return true;
}
- if (array().next(cursor().pos_))
+ if (cursor().pos_ != array().size()) {
+ plainRight();
return true;
- if (cursor().par_->idxRight(cursor().idx_, cursor().pos_))
+ }
+ if (cursor().par_->idxRight(cursor().idx_, cursor().pos_)) {
return true;
- if (!pop())
- return false;
- array().next(cursor().pos_);
- return true;
+ }
+ if (pop()) {
+ plainRight();
+ return true;
+ }
+ return false;
}
void MathCursor::first()
{
Cursor_.clear();
- push(formula_->par(), true);
+ push(outerPar(), true);
}
void MathCursor::last()
{
Cursor_.clear();
- push(formula_->par(), false);
+ push(outerPar(), false);
}
lastcode_ = LM_TC_MIN;
first();
- cursor().par_ = formula()->par();
+ cursor().par_ = outerPar();
while (1) {
cursor().idx_ = -1;
clearLastCode();
if (!cursor().par_->idxEnd(cursor().idx_, cursor().pos_)) {
pop();
- array().next(cursor().pos_);
+ ++cursor().pos_;
}
dump("end 2");
}
}
array().insert(cursor().pos_, c, t);
- array().next(cursor().pos_);
+ plainRight();
}
}
array().insert(cursor().pos_, p);
- ++cursor().pos_;
+ plainRight();
}
}
// delete empty cells if necessary
- if (cursor().pos_ == 0 && array().size() == 0) {
+ if (cursor().pos_ == 0 && array().empty()) {
bool popit;
bool removeit;
cursor().par_->idxDelete(cursor().idx_, popit, removeit);
bool MathCursor::toggleLimits()
{
- if (!prevIsInset())
- return false;
MathScriptInset * p = prevScriptInset();
+ if (!p)
+ return false;
int old = p->limits();
p->limits(old < 0 ? 1 : -1);
return old != p->limits();
p = new MathFuncInset(s);
} else {
switch (l->token) {
- case LM_TK_SYM:
- case LM_TK_BIGSYM:
+ case LM_TK_BIGSYM:
+ p = new MathBigopInset(l);
+ break;
+
case LM_TK_FUNCLIM:
+ p = new MathFuncLimInset(l);
+ break;
+
+ case LM_TK_SYM:
p = new MathSymbolInset(l);
break;
}
if (p) {
- bool oldsel = selection_;
- if (oldsel)
- selCut();
+ selCut();
insert(p);
if (p->nargs()) {
plainLeft();
right(); // do not push for e.g. MathSymbolInset
- if (oldsel)
- selPaste();
+ selPaste();
}
p->metrics(p->size());
}
theSelection.grab(*this);
theSelection.erase(*this);
selClear();
+ } else {
+ theSelection.clear();
}
}
void MathCursor::selHandle(bool sel)
{
- if (sel && !selection_)
- selStart();
- if (!sel && selection_)
- selClear();
+ if (sel == selection_)
+ return;
+
+ theSelection.clear();
+ Anchor_ = Cursor_;
+ selection_ = sel;
}
if (selection_)
return;
+ theSelection.clear();
Anchor_ = Cursor_;
selection_ = true;
}
void MathCursor::selClear()
{
+ seldump("selClear");
selection_ = false;
}
MathInset * MathCursor::prevInset() const
{
normalize();
- int c = cursor().pos_;
- if (!array().prev(c))
+ int pos = cursor().pos_;
+ if (!pos)
return 0;
- return array().nextInset(c);
+ return array().nextInset(pos - 1);
}
MathScriptInset * MathCursor::prevScriptInset() const
{
normalize();
- MathInset * p = array().prevInset(cursor().pos_);
+ MathInset * p = prevInset();
return (p && p->isScriptInset()) ? static_cast<MathScriptInset *>(p) : 0;
}
MathSpaceInset * MathCursor::prevSpaceInset() const
{
normalize();
- MathInset * p = array().prevInset(cursor().pos_);
+ MathInset * p = prevInset();
return (p && p->isSpaceInset()) ? static_cast<MathSpaceInset *>(p) : 0;
}
}
-bool MathCursor::nextIsInset() const
-{
- return cursor().pos_ < array().size() && MathIsInset(nextCode());
-}
-
-
-bool MathCursor::prevIsInset() const
-{
- return cursor().pos_ > 0 && MathIsInset(prevCode());
-}
-
-
int MathCursor::xpos() const
{
normalize();
void MathCursor::breakLine()
{
- MathMatrixInset * p = static_cast<MathMatrixInset *>(formula()->par());
+ MathMatrixInset * p = outerPar();
if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
p->mutate(LM_OT_EQNARRAY);
p->addRow(0);
MathCursorPos normal = Anchor_[Cursor_.size() - 1];
if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
// anchor is behind cursor -> move anchor behind the inset
- normal.cell().next(normal.pos_);
+ ++normal.pos_;
}
//lyxerr << "normalizing: from " << Anchor_[Anchor_.size() - 1] << " to "
// << normal << "\n";
{
return par_->idxRight(idx_, pos_);
}
+
+
+MathMatrixInset * MathCursor::outerPar() const
+{
+ return
+ static_cast<MathMatrixInset *>(const_cast<MathInset *>(formula_->par()));
+}