commit 3c0f46fb336fbfa3e8d76f00b05f5bd6daff4c72
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Tue Mar 10 15:53:25 2015 +0100

    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.

diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 919396c..46fa261 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -258,6 +258,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
 
 
@@ -2352,7 +2352,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 c3ae448..515bd36 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();
        ///

Reply via email to