* fix for buggy cursor logic due to multi bufferview support in MathMacros. It's much simpler now, even for simple single bufferview cases.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22562 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-01-14 21:53:49 +00:00
parent e0538043e4
commit 49daeaec29
2 changed files with 15 additions and 31 deletions

View File

@ -19,6 +19,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferView.h" #include "BufferView.h"
#include "CoordCache.h"
#include "Cursor.h" #include "Cursor.h"
#include "support/debug.h" #include "support/debug.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
@ -51,10 +52,13 @@ public:
/// ///
void metrics(MetricsInfo & mi, Dimension & dim) const { void metrics(MetricsInfo & mi, Dimension & dim) const {
mathMacro_.macro()->unlock(); mathMacro_.macro()->unlock();
mathMacro_.cell(idx_).metrics(mi, dim);
if (!mathMacro_.editMetrics(mi.base.bv) if (!mathMacro_.editMetrics(mi.base.bv)
&& mathMacro_.cell(idx_).empty()) && mathMacro_.cell(idx_).empty())
def_.metrics(mi, dim); def_.metrics(mi, dim);
else {
CoordCache & coords = mi.base.bv->coordCache();
dim = coords.arrays().dim(&mathMacro_.cell(idx_));
}
mathMacro_.macro()->lock(); mathMacro_.macro()->lock();
} }
/// ///
@ -138,14 +142,6 @@ void MathMacro::cursorPos(BufferView const & bv,
} }
int MathMacro::cursorIdx(Cursor const & cur) const {
for (size_t i = 0; i != cur.depth(); ++i)
if (&cur[i].inset() == this)
return cur[i].idx();
return -1;
}
bool MathMacro::editMode(BufferView const * bv) const { bool MathMacro::editMode(BufferView const * bv) const {
// find this in cursor trace // find this in cursor trace
Cursor const & cur = bv->cursor(); Cursor const & cur = bv->cursor();
@ -192,6 +188,10 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
} else { } else {
BOOST_ASSERT(macro_ != 0); BOOST_ASSERT(macro_ != 0);
// metrics are computed here for the cells,
// in the proxy we will then use the dim from the cache
InsetMathNest::metrics(mi);
// calculate metrics finally // calculate metrics finally
macro_->lock(); macro_->lock();
expanded_.cell(0).metrics(mi, dim); expanded_.cell(0).metrics(mi, dim);
@ -240,13 +240,6 @@ void MathMacro::updateMacro(MacroContext const & mc)
void MathMacro::updateRepresentation(Cursor const * bvCur) void MathMacro::updateRepresentation(Cursor const * bvCur)
{ {
// index of child where the cursor is (or -1 if none is edited)
int curIdx = -1;
if (bvCur) {
curIdx = cursorIdx(*bvCur);
previousCurIdx_[&bvCur->bv()] = curIdx;
}
// known macro? // known macro?
if (macro_ == 0) if (macro_ == 0)
return; return;
@ -269,13 +262,10 @@ void MathMacro::updateRepresentation(Cursor const * bvCur)
vector<MathData> values(nargs()); vector<MathData> values(nargs());
for (size_t i = 0; i < nargs(); ++i) { for (size_t i = 0; i < nargs(); ++i) {
ArgumentProxy * proxy; ArgumentProxy * proxy;
if (!cell(i).empty() if (i < defaults.size())
|| i >= defaults.size()
|| defaults[i].empty()
|| curIdx == (int)i)
proxy = new ArgumentProxy(*this, i);
else
proxy = new ArgumentProxy(*this, i, defaults[i]); proxy = new ArgumentProxy(*this, i, defaults[i]);
else
proxy = new ArgumentProxy(*this, i);
values[i].insert(0, MathAtom(proxy)); values[i].insert(0, MathAtom(proxy));
} }
@ -339,10 +329,8 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
pi.pain.rectangle(x, y - dim.asc, dim.wid, dim.height(), Color_mathmacroframe); pi.pain.rectangle(x, y - dim.asc, dim.wid, dim.height(), Color_mathmacroframe);
} }
// another argument selected or edit mode changed? // edit mode changed?
idx_type curIdx = cursorIdx(pi.base.bv->cursor()); if (editing_[pi.base.bv] != editMode(pi.base.bv))
if (previousCurIdx_[pi.base.bv] != curIdx
|| editing_[pi.base.bv] != editMode(pi.base.bv))
pi.base.bv->cursor().updateFlags(Update::Force); pi.base.bv->cursor().updateFlags(Update::Force);
} }

View File

@ -146,8 +146,6 @@ protected:
private: private:
/// ///
virtual Inset * clone() const; virtual Inset * clone() const;
/// the index of the cursor slice of the macro, or -1 if it is not edited
int cursorIdx(Cursor const & cur) const;
/// ///
bool editMode(BufferView const * bv) const; bool editMode(BufferView const * bv) const;
@ -159,8 +157,6 @@ private:
InsetMathSqrt expanded_; InsetMathSqrt expanded_;
/// number of arguments that were really attached /// number of arguments that were really attached
size_t attachedArgsNum_; size_t attachedArgsNum_;
/// cursor position during last draw
mutable std::map<BufferView const *, idx_type> previousCurIdx_;
/// optional argument attached? (only in DISPLAY_NORMAL mode) /// optional argument attached? (only in DISPLAY_NORMAL mode)
size_t optionals_; size_t optionals_;
/// fold mode to be set in next metrics call? /// fold mode to be set in next metrics call?