From 97c6e6d1bae4e823a3e251ea3faea37ce39df056 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 10 Mar 2015 15:53:25 +0100 Subject: [PATCH] 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. --- src/Cursor.cpp | 65 ++++++++++++++++++++++++++------------------------ src/Cursor.h | 8 +++---- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/Cursor.cpp b/src/Cursor.cpp index fe6f0e4be1..898eab3128 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -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(); } diff --git a/src/Cursor.h b/src/Cursor.h index 0f02129147..d5b5aa43ca 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -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(); /// -- 2.39.5