Do not sanitize the anchor of cursor when selection is not set

Additionally, move the code to write to a stream from Cursor to CursorData (so that debugging undo is easier). We loose x_target, but I am not sure it is important.

This is the second part of bug #9432.
This commit is contained in:
Jean-Marc Lasgouttes 2015-03-10 15:53:25 +01:00
parent 17e435c47e
commit 97c6e6d1ba
2 changed files with 38 additions and 35 deletions

View File

@ -261,6 +261,36 @@ CursorData::CursorData(DocIterator const & dit)
{}
ostream & operator<<(ostream & os, CursorData const & cur)
{
os << "\n cursor: | anchor:\n";
for (size_t i = 0, n = cur.depth(); i != n; ++i) {
os << " " << cur[i] << " | ";
if (i < cur.anchor_.depth())
os << cur.anchor_[i];
else
os << "-------------------------------";
os << "\n";
}
for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
os << "------------------------------- | " << cur.anchor_[i] << "\n";
}
os << " selection: " << cur.selection_
// << " x_target: " << cur.x_target_
<< " boundary: " << cur.boundary() << endl;
return os;
}
LyXErr & operator<<(LyXErr & os, CursorData const & cur)
{
os.stream() << cur;
return os;
}
// be careful: this is called from the bv's constructor, too, so
// bv functions are not yet available!
Cursor::Cursor(BufferView & bv)
@ -1291,36 +1321,6 @@ bool Cursor::selHandle(bool sel)
setSelection(sel);
return true;
}
ostream & operator<<(ostream & os, Cursor const & cur)
{
os << "\n cursor: | anchor:\n";
for (size_t i = 0, n = cur.depth(); i != n; ++i) {
os << " " << cur[i] << " | ";
if (i < cur.anchor_.depth())
os << cur.anchor_[i];
else
os << "-------------------------------";
os << "\n";
}
for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
os << "------------------------------- | " << cur.anchor_[i] << "\n";
}
os << " selection: " << cur.selection_
<< " x_target: " << cur.x_target_
<< " boundary: " << cur.boundary() << endl;
return os;
}
LyXErr & operator<<(LyXErr & os, Cursor const & cur)
{
os.stream() << cur;
return os;
}
} // namespace lyx
@ -2350,7 +2350,10 @@ void Cursor::sanitize()
{
setBuffer(&bv_->buffer());
DocIterator::sanitize();
anchor_.sanitize();
if (selection())
anchor_.sanitize();
else
resetAnchor();
}

View File

@ -88,6 +88,10 @@ public:
explicit CursorData(Buffer * buffer);
///
explicit CursorData(DocIterator const & dit);
/// output
friend std::ostream & operator<<(std::ostream & os, CursorData const & cur);
friend LyXErr & operator<<(LyXErr & os, CursorData const & cur);
protected:
/// the anchor position
DocIterator anchor_;
@ -345,10 +349,6 @@ public:
/// for stable iterators or Undo data.
void sanitize();
/// output
friend std::ostream & operator<<(std::ostream & os, Cursor const & cur);
friend LyXErr & operator<<(LyXErr & os, Cursor const & cur);
///
bool textUndo();
///