mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 02:14:50 +00:00
* reverting r18516, so no signals anymore in CursorSlices
* Alfredo Braunstein's patch to fix cursors properly * CursorSlice::lastpit() added git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18723 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
ee1cf6d67e
commit
c3363f110d
@ -42,10 +42,6 @@ CursorSlice::CursorSlice(Inset & p)
|
||||
: inset_(&p), idx_(0), pit_(0), pos_(0)
|
||||
{
|
||||
BOOST_ASSERT(inset_);
|
||||
boost::signal<void()> * destroyed_signal = inset_->destroyedSignal();
|
||||
if (destroyed_signal)
|
||||
inset_connection_ = destroyed_signal->connect(
|
||||
boost::bind(&CursorSlice::invalidate, this));
|
||||
}
|
||||
|
||||
|
||||
@ -55,22 +51,12 @@ CursorSlice::CursorSlice(CursorSlice const & cs)
|
||||
}
|
||||
|
||||
|
||||
CursorSlice::~CursorSlice()
|
||||
{
|
||||
inset_connection_.disconnect();
|
||||
}
|
||||
|
||||
|
||||
CursorSlice & CursorSlice::operator=(CursorSlice const & cs)
|
||||
{
|
||||
inset_ = cs.inset_;
|
||||
idx_ = cs.idx_;
|
||||
pit_ = cs.pit_;
|
||||
pos_ = cs.pos_;
|
||||
if (inset_ && inset_->destroyedSignal()) {
|
||||
inset_connection_ = inset_->destroyedSignal()->connect(
|
||||
boost::bind(&CursorSlice::invalidate, this));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -112,6 +98,14 @@ pos_type CursorSlice::lastpos() const
|
||||
}
|
||||
|
||||
|
||||
pit_type CursorSlice::lastpit() const
|
||||
{
|
||||
if (inset().inMathed())
|
||||
return 0;
|
||||
return text()->paragraphs().size() - 1;
|
||||
}
|
||||
|
||||
|
||||
CursorSlice::row_type CursorSlice::row() const
|
||||
{
|
||||
BOOST_ASSERT(asInsetMath());
|
||||
|
@ -41,7 +41,7 @@ class Paragraph;
|
||||
// that of MathData and Text should vanish. They are conceptually the
|
||||
// same (now...)
|
||||
|
||||
class CursorSlice : public boost::signals::trackable {
|
||||
class CursorSlice {
|
||||
public:
|
||||
/// Those needs inset_ access.
|
||||
///@{
|
||||
@ -63,8 +63,6 @@ public:
|
||||
///
|
||||
explicit CursorSlice(Inset &);
|
||||
///
|
||||
virtual ~CursorSlice();
|
||||
///
|
||||
CursorSlice & operator=(CursorSlice const &);
|
||||
///
|
||||
bool isValid() const;
|
||||
@ -81,6 +79,8 @@ public:
|
||||
pit_type pit() const { return pit_; }
|
||||
/// set the offset of the paragraph this cursor is in
|
||||
pit_type & pit() { return pit_; }
|
||||
/// return the last paragraph offset this cursor is in
|
||||
pit_type lastpit() const;
|
||||
/// increments the paragraph this cursor is in
|
||||
void incrementPar();
|
||||
/// decrements the paragraph this cursor is in
|
||||
@ -158,8 +158,6 @@ private:
|
||||
bool pit_valid_;
|
||||
/// position in this cell
|
||||
pos_type pos_;
|
||||
/// connection to referred \c inset_ destruction signal.
|
||||
boost::signals::connection inset_connection_;
|
||||
};
|
||||
|
||||
/// test for equality
|
||||
|
@ -4,6 +4,7 @@
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author André Pönitz
|
||||
* \author Alfredo Braunstein
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -560,53 +561,55 @@ void DocIterator::updateInsets(Inset * inset)
|
||||
|
||||
bool DocIterator::fixIfBroken()
|
||||
{
|
||||
bool fixed = false;
|
||||
|
||||
for (size_t i = slices_.size() - 1; i != 0; --i)
|
||||
if (!slices_[i].isValid()) {
|
||||
pop_back();
|
||||
fixed = true;
|
||||
// Go through the slice stack from the bottom.
|
||||
// Check that all coordinates (idx, pit, pos) are correct and
|
||||
// that the inset is the one which is claimed to be there
|
||||
Inset * inset = &slices_[0].inset();
|
||||
size_t i = 0;
|
||||
size_t n = slices_.size();
|
||||
for (; i != n; ++i) {
|
||||
CursorSlice & cs = slices_[i];
|
||||
if (&cs.inset() != inset) {
|
||||
// the whole slice is wrong, chop off this as well
|
||||
--i;
|
||||
LYXERR(Debug::DEBUG) << "fixIfBroken(): inset changed" << endl;
|
||||
break;
|
||||
} else if (cs.idx() > cs.lastidx()) {
|
||||
cs.idx() = cs.lastidx();
|
||||
cs.pit() = cs.lastpit();
|
||||
cs.pos() = cs.lastpos();
|
||||
LYXERR(Debug::DEBUG) << "fixIfBroken(): idx fixed" << endl;
|
||||
break;
|
||||
} else if (cs.pit() > cs.lastpit()) {
|
||||
cs.pit() = cs.lastpit();
|
||||
cs.pos() = cs.lastpos();
|
||||
LYXERR(Debug::DEBUG) << "fixIfBroken(): pit fixed" << endl;
|
||||
break;
|
||||
} else if (cs.pos() > cs.lastpos()) {
|
||||
cs.pos() = cs.lastpos();
|
||||
LYXERR(Debug::DEBUG) << "fixIfBroken(): pos fixed" << endl;
|
||||
break;
|
||||
} else if (i != n - 1 && cs.pos() != cs.lastpos()) {
|
||||
// get inset which is supposed to be in the next slice
|
||||
if (cs.inset().inMathed())
|
||||
inset = (cs.cell().begin() + cs.pos())->nucleus();
|
||||
else if (cs.paragraph().isInset(cs.pos()))
|
||||
inset = cs.paragraph().getInset(cs.pos());
|
||||
else {
|
||||
// there are slices left, so there must be another inset
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The top level CursorSlice should always be valid.
|
||||
BOOST_ASSERT(slices_[0].isValid());
|
||||
|
||||
if (idx() > lastidx()) {
|
||||
lyxerr << "wrong idx " << idx()
|
||||
<< ", max is " << lastidx()
|
||||
<< " at level " << depth()
|
||||
<< ". Trying to correct this." << endl;
|
||||
lyxerr << "old: " << *this << endl;
|
||||
for (size_t i = idx(); i != lastidx(); --i)
|
||||
pop_back();
|
||||
idx() = lastidx();
|
||||
pit() = lastpit();
|
||||
pos() = lastpos();
|
||||
fixed = true;
|
||||
}
|
||||
else if (pit() > lastpit()) {
|
||||
lyxerr << "wrong pit " << pit()
|
||||
<< ", max is " << lastpit()
|
||||
<< " at level " << depth()
|
||||
<< ". Trying to correct this." << endl;
|
||||
lyxerr << "old: " << *this << endl;
|
||||
pit() = lastpit();
|
||||
pos() = 0;
|
||||
fixed = true;
|
||||
}
|
||||
else if (pos() > lastpos()) {
|
||||
lyxerr << "wrong pos " << pos()
|
||||
<< ", max is " << lastpos()
|
||||
<< " at level " << depth()
|
||||
<< ". Trying to correct this." << endl;
|
||||
lyxerr << "old: " << *this << endl;
|
||||
pos() = lastpos();
|
||||
fixed = true;
|
||||
}
|
||||
if (fixed) {
|
||||
lyxerr << "new: " << *this << endl;
|
||||
}
|
||||
return fixed;
|
||||
// Did we make it through the whole slice stack? Otherwise there
|
||||
// was a problem at slice i, and we have to chop off above
|
||||
if (i < n) {
|
||||
LYXERR(Debug::DEBUG) << "fixIfBroken(): cursor chopped at " << i << endl;
|
||||
resize(i + 1);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user