fix nasty bug when inserting labels when cursor was in nested array

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3189 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-12-11 15:04:02 +00:00
parent 574031d689
commit 1d8a1db27f
8 changed files with 63 additions and 70 deletions

View File

@ -364,7 +364,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
vector<string> const InsetFormula::getLabelList() const vector<string> const InsetFormula::getLabelList() const
{ {
return mat()->getLabelList(); return hull()->getLabelList();
} }
@ -388,9 +388,9 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
//lyxerr << "toggling all numbers\n"; //lyxerr << "toggling all numbers\n";
if (display()) { if (display()) {
bv->lockedInsetStoreUndo(Undo::INSERT); bv->lockedInsetStoreUndo(Undo::INSERT);
bool old = mat()->numberedType(); bool old = hull()->numberedType();
for (MathInset::row_type row = 0; row < par_->nrows(); ++row) for (MathInset::row_type row = 0; row < par_->nrows(); ++row)
mat()->numbered(row, !old); hull()->numbered(row, !old);
bv->owner()->message(old ? _("No number") : _("Number")); bv->owner()->message(old ? _("No number") : _("Number"));
updateLocal(bv, true); updateLocal(bv, true);
} }
@ -402,10 +402,10 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
//lyxerr << "toggling line number\n"; //lyxerr << "toggling line number\n";
if (display()) { if (display()) {
bv->lockedInsetStoreUndo(Undo::INSERT); bv->lockedInsetStoreUndo(Undo::INSERT);
MathCursor::row_type row = mathcursor->row(); MathCursor::row_type row = mathcursor->hullRow();
bool old = mat()->numbered(row); bool old = hull()->numbered(row);
bv->owner()->message(old ? _("No number") : _("Number")); bv->owner()->message(old ? _("No number") : _("Number"));
mat()->numbered(row, !old); hull()->numbered(row, !old);
updateLocal(bv, true); updateLocal(bv, true);
} }
break; break;
@ -415,8 +415,8 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
{ {
bv->lockedInsetStoreUndo(Undo::INSERT); bv->lockedInsetStoreUndo(Undo::INSERT);
MathCursor::row_type row = mathcursor->row(); MathCursor::row_type row = mathcursor->hullRow();
string old_label = mat()->label(row); string old_label = hull()->label(row);
string new_label = arg; string new_label = arg;
if (new_label.empty()) { if (new_label.empty()) {
@ -425,8 +425,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
pair<bool, string> const res = old_label.empty() pair<bool, string> const res = old_label.empty()
? Alert::askForText(_("Enter new label to insert:"), default_label) ? Alert::askForText(_("Enter new label to insert:"), default_label)
: Alert::askForText(_("Enter label:"), old_label); : Alert::askForText(_("Enter label:"), old_label);
lyxerr << "res: " << res.first << " - '" << res.second << "'\n";
if (!res.first) if (!res.first)
break; break;
new_label = frontStrip(strip(res.second)); new_label = frontStrip(strip(res.second));
@ -437,13 +435,13 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
if (!new_label.empty()) { if (!new_label.empty()) {
lyxerr << "setting label to '" << new_label << "'\n"; lyxerr << "setting label to '" << new_label << "'\n";
mat()->numbered(row, true); hull()->numbered(row, true);
} }
if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label)) if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
bv->redraw(); bv->redraw();
mat()->label(row, new_label); hull()->label(row, new_label);
updateLocal(bv, true); updateLocal(bv, true);
break; break;
@ -455,7 +453,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
int x; int x;
int y; int y;
mathcursor->getPos(x, y); mathcursor->getPos(x, y);
mat()->mutate(arg); hull()->mutate(arg);
mathcursor->setPos(x, y); mathcursor->setPos(x, y);
mathcursor->normalize(); mathcursor->normalize();
updateLocal(bv, true); updateLocal(bv, true);
@ -477,10 +475,10 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
int x = 0; int x = 0;
int y = 0; int y = 0;
mathcursor->getPos(x, y); mathcursor->getPos(x, y);
if (mat()->getType() == LM_OT_SIMPLE) if (hull()->getType() == LM_OT_SIMPLE)
mat()->mutate(LM_OT_EQUATION); hull()->mutate(LM_OT_EQUATION);
else else
mat()->mutate(LM_OT_SIMPLE); hull()->mutate(LM_OT_SIMPLE);
mathcursor->setPos(x, y); mathcursor->setPos(x, y);
mathcursor->normalize(); mathcursor->normalize();
updateLocal(bv, true); updateLocal(bv, true);
@ -495,16 +493,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
break; break;
} }
case LFUN_MATH_COLUMN_INSERT:
{
if (mat()->getType() == LM_OT_ALIGN)
mat()->mutate(LM_OT_ALIGNAT);
mat()->addCol(mat()->ncols());
mathcursor->normalize();
updateLocal(bv, true);
break;
}
default: default:
result = InsetFormulaBase::localDispatch(bv, action, arg); result = InsetFormulaBase::localDispatch(bv, action, arg);
} }
@ -538,7 +526,7 @@ void InsetFormula::handleExtern(const string & arg)
MathArray ar; MathArray ar;
if (needEqnArray(extra)) { if (needEqnArray(extra)) {
mathcursor->last(); mathcursor->last();
mathcursor->readLine(ar); //mathcursor->readLine(ar);
mathcursor->breakLine(); mathcursor->breakLine();
} else if (selected) { } else if (selected) {
mathcursor->selGet(ar); mathcursor->selGet(ar);
@ -557,18 +545,18 @@ void InsetFormula::handleExtern(const string & arg)
bool InsetFormula::display() const bool InsetFormula::display() const
{ {
return mat()->getType() != LM_OT_SIMPLE; return hull()->getType() != LM_OT_SIMPLE;
} }
MathHullInset const * InsetFormula::mat() const MathHullInset const * InsetFormula::hull() const
{ {
lyx::Assert(par_->asHullInset()); lyx::Assert(par_->asHullInset());
return par_->asHullInset(); return par_->asHullInset();
} }
MathHullInset * InsetFormula::mat() MathHullInset * InsetFormula::hull()
{ {
lyx::Assert(par_->asHullInset()); lyx::Assert(par_->asHullInset());
return par_->asHullInset(); return par_->asHullInset();
@ -616,5 +604,5 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const
MathInsetTypes InsetFormula::getType() const MathInsetTypes InsetFormula::getType() const
{ {
return mat()->getType(); return hull()->getType();
} }

View File

@ -82,10 +82,10 @@ private:
bool display() const; bool display() const;
/// available in AMS only? /// available in AMS only?
bool ams() const; bool ams() const;
/// Access /// access to hull
MathHullInset * mat(); MathHullInset * hull();
/// Access /// access to hull
MathHullInset const * mat() const; MathHullInset const * hull() const;
/// ///
void handleExtern(string const & arg); void handleExtern(string const & arg);

View File

@ -521,8 +521,11 @@ void MathCursor::delLine()
return; return;
} }
if (par()->nrows() > 1) if (par()->nrows() > 1) {
par()->delRow(row()); // grid are the only things with more than one row...
lyx::Assert(par()->asGridInset());
par()->asGridInset()->delRow(hullRow());
}
if (idx() > par()->nargs()) if (idx() > par()->nargs())
idx() = par()->nargs(); idx() = par()->nargs();
@ -929,15 +932,15 @@ MathCursor::size_type MathCursor::size() const
} }
MathCursor::col_type MathCursor::col() const MathCursor::col_type MathCursor::hullCol() const
{ {
return par()->col(idx()); return Cursor_[0].par_->nucleus()->asGridInset()->col(Cursor_[0].idx_);
} }
MathCursor::row_type MathCursor::row() const MathCursor::row_type MathCursor::hullRow() const
{ {
return par()->row(idx()); return Cursor_[0].par_->nucleus()->asGridInset()->row(Cursor_[0].idx_);
} }
@ -1052,11 +1055,11 @@ void MathCursor::breakLine()
idx() = 0; idx() = 0;
pos() = size(); pos() = size();
} else { } else {
p->addRow(row()); p->addRow(hullRow());
// split line // split line
const row_type r = row(); const row_type r = hullRow();
for (col_type c = col() + 1; c < p->ncols(); ++c) for (col_type c = hullCol() + 1; c < p->ncols(); ++c)
p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c))); p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
// split cell // split cell
@ -1066,12 +1069,12 @@ void MathCursor::breakLine()
} }
void MathCursor::readLine(MathArray & ar) const //void MathCursor::readLine(MathArray & ar) const
{ //{
idx_type base = row() * par()->ncols(); // idx_type base = row() * par()->ncols();
for (idx_type off = 0; off < par()->ncols(); ++off) // for (idx_type off = 0; off < par()->ncols(); ++off)
ar.push_back(par()->cell(base + off)); // ar.push_back(par()->cell(base + off));
} //}
char MathCursor::valign() const char MathCursor::valign() const

View File

@ -171,11 +171,9 @@ public:
/// ///
char halign() const; char halign() const;
/// ///
col_type ncols() const; col_type hullCol() const;
/// ///
col_type col() const; row_type hullRow() const;
///
row_type row() const;
/// make sure cursor position is valid /// make sure cursor position is valid
void normalize() const; void normalize() const;

View File

@ -131,13 +131,13 @@ public:
void idxDeleteRange(idx_type, idx_type); void idxDeleteRange(idx_type, idx_type);
/// ///
void addRow(row_type); virtual void addRow(row_type);
/// ///
void delRow(row_type); virtual void delRow(row_type);
/// ///
void addCol(col_type); virtual void addCol(col_type);
/// ///
void delCol(col_type); virtual void delCol(col_type);
/// ///
virtual void appendRow(); virtual void appendRow();
/// ///

View File

@ -5,12 +5,13 @@
#endif #endif
#include "math_hullinset.h" #include "math_hullinset.h"
#include "math_mathmlstream.h"
#include "math_streamstr.h"
#include "math_support.h" #include "math_support.h"
#include "debug.h" #include "debug.h"
#include "Painter.h" #include "Painter.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "math_mathmlstream.h" #include "support/LAssert.h"
#include "math_streamstr.h"
#include <vector> #include <vector>
@ -191,6 +192,8 @@ void MathHullInset::draw(Painter & pain, int x, int y) const
string MathHullInset::label(row_type row) const string MathHullInset::label(row_type row) const
{ {
row_type n = nrows();
lyx::Assert(row < n);
return label_[row]; return label_[row];
} }
@ -687,3 +690,10 @@ void MathHullInset::mathmlize(MathMLStream & os) const
} }
void MathHullInset::check() const
{
lyx::Assert(nonum_.size() == nrows());
lyx::Assert(label_.size() == nrows());
}

View File

@ -47,9 +47,9 @@ public:
/// ///
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;
/// identifies MatrixInsets /// identifies MatrixInsets
virtual MathHullInset const * asHullInset() const { return this; } MathHullInset const * asHullInset() const { return this; }
/// identifies HullInset /// identifies HullInset
virtual MathHullInset * asHullInset() { return this; } MathHullInset * asHullInset() { return this; }
/// ///
void addRow(row_type); void addRow(row_type);
@ -94,6 +94,8 @@ private:
void glueall(); void glueall();
/// ///
string nicelabel(row_type row) const; string nicelabel(row_type row) const;
/// consistency check
void check() const;
/// ///
MathInsetTypes objtype_; MathInsetTypes objtype_;

View File

@ -179,14 +179,6 @@ public:
virtual int cellXOffset(idx_type) const { return 0; } virtual int cellXOffset(idx_type) const { return 0; }
/// any additional y-offset when drawing a cell? /// any additional y-offset when drawing a cell?
virtual int cellYOffset(idx_type) const { return 0; } virtual int cellYOffset(idx_type) const { return 0; }
/// add a row after a given one
virtual void addRow(row_type) {}
/// delete a given row
virtual void delRow(row_type) {}
/// add a column after a given one
virtual void addCol(col_type) {}
/// delete a given row
virtual void delCol(col_type) {}
/// identifies certain types of insets /// identifies certain types of insets
virtual MathArrayInset * asArrayInset() { return 0; } virtual MathArrayInset * asArrayInset() { return 0; }