]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
PDF-form.lyx: add a note
[lyx.git] / src / Cursor.cpp
index fe6f0e4be1b303bfc7cd0342f81a24bf46f24c63..45720973edbc89c3db3d7f1445ec3076d02ba079 100644 (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();
 }
 
 
@@ -2473,15 +2476,15 @@ void Cursor::endUndoGroup() const
 }
 
 
-void Cursor::recordUndo(UndoKind kind, pit_type from, pit_type to) const
+void Cursor::recordUndo(pit_type from, pit_type to) const
 {
-       buffer()->undo().recordUndo(*this, kind, from, to);
+       buffer()->undo().recordUndo(*this, from, to);
 }
 
 
-void Cursor::recordUndo(UndoKind kind, pit_type from) const
+void Cursor::recordUndo(pit_type from) const
 {
-       buffer()->undo().recordUndo(*this, kind, from);
+       buffer()->undo().recordUndo(*this, from, pit());
 }
 
 
@@ -2491,9 +2494,16 @@ void Cursor::recordUndo(UndoKind kind) const
 }
 
 
-void Cursor::recordUndoInset(UndoKind kind, Inset const * inset) const
+void Cursor::recordUndoInset(Inset const * in) const
 {
-       buffer()->undo().recordUndoInset(*this, kind, inset);
+       if (!in || in == &inset()) {
+               CursorData c = *this;
+               c.pop_back();
+               buffer()->undo().recordUndo(c, c.pit(), c.pit());
+       } else if (in == nextInset())
+               recordUndo();
+       else
+               LYXERR0("Inset not found, no undo element added.");
 }
 
 
@@ -2517,7 +2527,7 @@ void Cursor::recordUndoSelection() const
                else
                        recordUndo();
        } else {
-               buffer()->undo().recordUndo(*this, ATOMIC_UNDO,
+               buffer()->undo().recordUndo(*this,
                        selBegin().pit(), selEnd().pit());
        }
 }