mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +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)
|
: inset_(&p), idx_(0), pit_(0), pos_(0)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(inset_);
|
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)
|
CursorSlice & CursorSlice::operator=(CursorSlice const & cs)
|
||||||
{
|
{
|
||||||
inset_ = cs.inset_;
|
inset_ = cs.inset_;
|
||||||
idx_ = cs.idx_;
|
idx_ = cs.idx_;
|
||||||
pit_ = cs.pit_;
|
pit_ = cs.pit_;
|
||||||
pos_ = cs.pos_;
|
pos_ = cs.pos_;
|
||||||
if (inset_ && inset_->destroyedSignal()) {
|
|
||||||
inset_connection_ = inset_->destroyedSignal()->connect(
|
|
||||||
boost::bind(&CursorSlice::invalidate, this));
|
|
||||||
}
|
|
||||||
return *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
|
CursorSlice::row_type CursorSlice::row() const
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(asInsetMath());
|
BOOST_ASSERT(asInsetMath());
|
||||||
|
@ -41,7 +41,7 @@ class Paragraph;
|
|||||||
// that of MathData and Text should vanish. They are conceptually the
|
// that of MathData and Text should vanish. They are conceptually the
|
||||||
// same (now...)
|
// same (now...)
|
||||||
|
|
||||||
class CursorSlice : public boost::signals::trackable {
|
class CursorSlice {
|
||||||
public:
|
public:
|
||||||
/// Those needs inset_ access.
|
/// Those needs inset_ access.
|
||||||
///@{
|
///@{
|
||||||
@ -63,8 +63,6 @@ public:
|
|||||||
///
|
///
|
||||||
explicit CursorSlice(Inset &);
|
explicit CursorSlice(Inset &);
|
||||||
///
|
///
|
||||||
virtual ~CursorSlice();
|
|
||||||
///
|
|
||||||
CursorSlice & operator=(CursorSlice const &);
|
CursorSlice & operator=(CursorSlice const &);
|
||||||
///
|
///
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
@ -81,6 +79,8 @@ public:
|
|||||||
pit_type pit() const { return pit_; }
|
pit_type pit() const { return pit_; }
|
||||||
/// set the offset of the paragraph this cursor is in
|
/// set the offset of the paragraph this cursor is in
|
||||||
pit_type & pit() { return pit_; }
|
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
|
/// increments the paragraph this cursor is in
|
||||||
void incrementPar();
|
void incrementPar();
|
||||||
/// decrements the paragraph this cursor is in
|
/// decrements the paragraph this cursor is in
|
||||||
@ -158,8 +158,6 @@ private:
|
|||||||
bool pit_valid_;
|
bool pit_valid_;
|
||||||
/// position in this cell
|
/// position in this cell
|
||||||
pos_type pos_;
|
pos_type pos_;
|
||||||
/// connection to referred \c inset_ destruction signal.
|
|
||||||
boost::signals::connection inset_connection_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// test for equality
|
/// test for equality
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
* Licence details can be found in the file COPYING.
|
* Licence details can be found in the file COPYING.
|
||||||
*
|
*
|
||||||
* \author André Pönitz
|
* \author André Pönitz
|
||||||
|
* \author Alfredo Braunstein
|
||||||
*
|
*
|
||||||
* Full author contact details are available in file CREDITS.
|
* Full author contact details are available in file CREDITS.
|
||||||
*/
|
*/
|
||||||
@ -560,53 +561,55 @@ void DocIterator::updateInsets(Inset * inset)
|
|||||||
|
|
||||||
bool DocIterator::fixIfBroken()
|
bool DocIterator::fixIfBroken()
|
||||||
{
|
{
|
||||||
bool fixed = false;
|
// Go through the slice stack from the bottom.
|
||||||
|
// Check that all coordinates (idx, pit, pos) are correct and
|
||||||
for (size_t i = slices_.size() - 1; i != 0; --i)
|
// that the inset is the one which is claimed to be there
|
||||||
if (!slices_[i].isValid()) {
|
Inset * inset = &slices_[0].inset();
|
||||||
pop_back();
|
size_t i = 0;
|
||||||
fixed = true;
|
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.
|
// Did we make it through the whole slice stack? Otherwise there
|
||||||
BOOST_ASSERT(slices_[0].isValid());
|
// was a problem at slice i, and we have to chop off above
|
||||||
|
if (i < n) {
|
||||||
if (idx() > lastidx()) {
|
LYXERR(Debug::DEBUG) << "fixIfBroken(): cursor chopped at " << i << endl;
|
||||||
lyxerr << "wrong idx " << idx()
|
resize(i + 1);
|
||||||
<< ", max is " << lastidx()
|
return true;
|
||||||
<< " at level " << depth()
|
} else
|
||||||
<< ". Trying to correct this." << endl;
|
return false;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user