]> git.lyx.org Git - features.git/commitdiff
bug 344: Fixed loosing cursor/selection on buffer-switch
authorJürgen Vigna <jug@sad.it>
Sun, 17 Jul 2005 14:29:35 +0000 (14:29 +0000)
committerJürgen Vigna <jug@sad.it>
Sun, 17 Jul 2005 14:29:35 +0000 (14:29 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10286 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView_pimpl.C
src/ChangeLog
src/buffer.C
src/buffer.h

index 1c52d6e331492a1cd2398a980ab57fe763a184ee..4ff3e93b293df92569d2bf73f3afa548e6207a4a 100644 (file)
@@ -323,8 +323,14 @@ void BufferView::Pimpl::setBuffer(Buffer * b)
        lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
                            << "[ b = " << b << "]" << endl;
 
-       if (buffer_)
+       if (buffer_) {
                disconnectBuffer();
+               // Save the actual cursor position and anchor inside the
+               // buffer so that it can be restored in case we rechange
+               // to this buffer later on.
+               buffer_->saveCursor(cursor_.selectionBegin(),
+                                   cursor_.selectionEnd());
+       }
 
        // If we are closing current buffer, switch to the first in
        // buffer list.
@@ -353,11 +359,18 @@ void BufferView::Pimpl::setBuffer(Buffer * b)
                lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
                                    << "Buffer addr: " << buffer_ << endl;
                connectBuffer(*buffer_);
-
                cursor_.push(buffer_->inset());
                cursor_.resetAnchor();
                buffer_->text().init(bv_);
                buffer_->text().setCurrentFont(cursor_);
+               if (buffer_->getCursor().size() > 0 &&
+                   buffer_->getAnchor().size() > 0)
+               {
+                       cursor_.setCursor(buffer_->getAnchor().asDocIterator(&(buffer_->inset())));
+                       cursor_.resetAnchor();
+                       cursor_.setCursor(buffer_->getCursor().asDocIterator(&(buffer_->inset())));
+                       cursor_.setSelection();
+               }
 
                // Buffer-dependent dialogs should be updated or
                // hidden. This should go here because some dialogs (eg ToC)
index e7a4e68a4d57b9f23288dab78cd0534838d84479..c8874df205ef3cbb8b3f3eb8dd0a3d6efd9e424a 100644 (file)
@@ -1,3 +1,13 @@
+2005-07-17  Juergen Vigna  <jug@lyx.org>
+
+       * BufferView_pimpl.C (setBuffer): save/restore the
+       cursor/selection when switching buffers
+
+       * buffer.h: 
+       * buffer.C (saveCursor): add saveDocumentIterators to save the
+       cursor when switching buffer.
+
+
 2005-07-17  Michael Schmitt  <michqel.schmitt@teststep.org>
 
        * debug.C: fix typo
index 83050e655890b249bd63a6b7ea08dccf35937a70..0c379584fa5acd8acd086629b1659c8ebb9bae95 100644 (file)
@@ -1542,3 +1542,9 @@ void Buffer::buildMacros()
                }
        }
 }
+
+void Buffer::saveCursor(StableDocIterator cur, StableDocIterator anc)
+{
+       cursor_ = cur;
+       anchor_ = anc;
+}
index 26ae13f928b9d2914202f56bb5a1d8f99331867e..f181ded04bd897df4b3124d883ba326970083c2a 100644 (file)
@@ -14,6 +14,8 @@
 
 #include "InsetList.h"
 
+#include "dociterator.h"
+
 #include "support/limited_stack.h"
 #include "support/types.h"
 
@@ -46,6 +48,7 @@ class ParIterator;
 class TeXErrors;
 class TexRow;
 class Undo;
+class StableDocIterator;
 
 
 /** The buffer object.
@@ -307,9 +310,10 @@ public:
        /// Set by buffer_funcs' newFile.
        void fully_loaded(bool);
 
-       ///
+       /// Our main text (inside the top InsetText)
        LyXText & text() const;
-       ///
+
+       /// Our top InsetText!
        InsetBase & inset() const;
 
        //
@@ -323,6 +327,12 @@ public:
        MacroData const & getMacro(std::string const & name) const;
        ///
        void insertMacro(std::string const & name, MacroData const & data);
+       ///
+       void saveCursor(StableDocIterator cursor, StableDocIterator anchor);
+       ///
+       StableDocIterator getCursor() const { return cursor_; }
+       ///
+       StableDocIterator getAnchor() const { return anchor_; }
 
 private:
        /** Inserts a file into a document
@@ -338,6 +348,12 @@ private:
        class Impl;
        /// The pointer never changes although *pimpl_'s contents may.
        boost::scoped_ptr<Impl> const pimpl_;
+
+       /// Save the cursor Position on Buffer switch
+       /// this would not be needed if every Buffer would have
+       /// it's BufferView, this should be FIXED in future.
+       StableDocIterator cursor_;
+       StableDocIterator anchor_;
 };
 
 #endif