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

View File

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

View File

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

View File

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

View File

@ -131,13 +131,13 @@ public:
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();
///

View File

@ -5,12 +5,13 @@
#endif
#include "math_hullinset.h"
#include "math_mathmlstream.h"
#include "math_streamstr.h"
#include "math_support.h"
#include "debug.h"
#include "Painter.h"
#include "LaTeXFeatures.h"
#include "math_mathmlstream.h"
#include "math_streamstr.h"
#include "support/LAssert.h"
#include <vector>
@ -191,6 +192,8 @@ void MathHullInset::draw(Painter & pain, int x, int y) const
string MathHullInset::label(row_type row) const
{
row_type n = nrows();
lyx::Assert(row < n);
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;
/// identifies MatrixInsets
virtual MathHullInset const * asHullInset() const { return this; }
MathHullInset const * asHullInset() const { return this; }
/// identifies HullInset
virtual MathHullInset * asHullInset() { return this; }
MathHullInset * asHullInset() { return this; }
///
void addRow(row_type);
@ -94,6 +94,8 @@ private:
void glueall();
///
string nicelabel(row_type row) const;
/// consistency check
void check() const;
///
MathInsetTypes objtype_;

View File

@ -179,14 +179,6 @@ public:
virtual int cellXOffset(idx_type) const { return 0; }
/// any additional y-offset when drawing a cell?
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
virtual MathArrayInset * asArrayInset() { return 0; }