From: Jürgen Vigna Date: Sun, 17 Jul 2005 14:29:35 +0000 (+0000) Subject: bug 344: Fixed loosing cursor/selection on buffer-switch X-Git-Tag: 1.6.10~14060 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=a685a01ef72203f75cef81a7fe5f0f0ab7ba332d;p=lyx.git bug 344: Fixed loosing cursor/selection on buffer-switch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10286 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 1c52d6e331..4ff3e93b29 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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) diff --git a/src/ChangeLog b/src/ChangeLog index e7a4e68a4d..c8874df205 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2005-07-17 Juergen Vigna + + * 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 * debug.C: fix typo diff --git a/src/buffer.C b/src/buffer.C index 83050e6558..0c379584fa 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1542,3 +1542,9 @@ void Buffer::buildMacros() } } } + +void Buffer::saveCursor(StableDocIterator cur, StableDocIterator anc) +{ + cursor_ = cur; + anchor_ = anc; +} diff --git a/src/buffer.h b/src/buffer.h index 26ae13f928..f181ded04b 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -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 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