http://bugzilla.lyx.org/show_bug.cgi?id=3201
This turned to be out more complicated than I thought, because both the cursor
and the scrollbar position have to be saved for each buffer separately.
Attached is what I came up with.
Opinions?
Jürgen
Index: src/frontends/qt4/QDocument.cpp
===================================================================
--- src/frontends/qt4/QDocument.cpp (Revision 18139)
+++ src/frontends/qt4/QDocument.cpp (Arbeitskopie)
@@ -746,6 +746,11 @@
// preamble
params.preamble =
fromqstr(preambleModule->preambleTE->document()->toPlainText());
+ // store cursor and scrollbar position
+ preamble_coords_[&form_->controller().buffer()].first =
+ preambleModule->preambleTE->textCursor().position();
+ preamble_coords_[&form_->controller().buffer()].second =
+ preambleModule->preambleTE->verticalScrollBar()->value();
// biblio
params.setCiteEngine(biblio::ENGINE_BASIC);
@@ -1023,6 +1028,16 @@
// preamble
QString preamble = toqstr(params.preamble);
preambleModule->preambleTE->document()->setPlainText(preamble);
+ // restore cursor and scrollbar position, if possible
+ Buffer const & buffer = form_->controller().buffer();
+ if (preamble_coords_.find(&buffer) != preamble_coords_.end()) {
+ QTextCursor cur = preambleModule->preambleTE->textCursor();
+ cur.setPosition(preamble_coords_[&buffer].first);
+ preambleModule->preambleTE->setTextCursor(cur);
+ preambleModule->preambleTE->verticalScrollBar()->setValue(
+ preamble_coords_[&buffer].second);
+ preambleModule->preambleTE->setFocus();
+ }
// biblio
biblioModule->citeDefaultRB->setChecked(
Index: src/frontends/qt4/QDocument.h
===================================================================
--- src/frontends/qt4/QDocument.h (Revision 18139)
+++ src/frontends/qt4/QDocument.h (Arbeitskopie)
@@ -29,6 +29,7 @@
#include <QCloseEvent>
#include <QDialog>
+#include <QScrollBar>
#include <vector>
#include <string>
@@ -109,6 +110,8 @@
/// FIXME
std::vector<std::string> lang_;
+ ///
+ std::map<Buffer const *, std::pair<int, int> > preamble_coords_;
};
Index: src/frontends/controllers/ControlDocument.h
===================================================================
--- src/frontends/controllers/ControlDocument.h (Revision 18139)
+++ src/frontends/controllers/ControlDocument.h (Arbeitskopie)
@@ -50,6 +50,8 @@
///
BufferParams & params() const;
///
+ Buffer const & buffer() const { return kernel().buffer(); }
+ ///
void setLanguage() const;
///
void saveAsDefault() const;