diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 61b196fbb5..6e2ad8115a 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -214,6 +214,12 @@ void BufferView::setBuffer(Buffer * b) cursor_.push(buffer_->inset()); cursor_.resetAnchor(); buffer_->text().setCurrentFont(cursor_); + + // Update the metrics now that we have a proper Cursor. + updateMetrics(false); + + // FIXME: This code won't be needed once we switch to + // "one Buffer" / "one BufferView". if (buffer_->getCursor().size() > 0 && buffer_->getAnchor().size() > 0) { @@ -227,12 +233,17 @@ void BufferView::setBuffer(Buffer * b) // Make sure that the restored cursor is not broken. This can happen for // example if this Buffer has been modified by another view. cursor_.fixIfBroken(); + + if (fitCursor()) + // Update the metrics if the cursor new position was off screen. + updateMetrics(false); } - updateMetrics(false); + if (graphics::Previews::status() != LyXRC::PREVIEW_OFF) graphics::Previews::get().generateBufferPreviews(*buffer_); } + void BufferView::resize() { if (!buffer_) diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index f549847e39..27f558a5fb 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -2089,16 +2089,8 @@ void LyXFunc::closeBuffer() // goto bookmark to update bookmark pit. for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i) gotoBookmark(i+1, false, false); - if (theBufferList().close(lyx_view_->buffer(), true) && !quitting) { - if (theBufferList().empty()) { - // need this otherwise SEGV may occur while - // trying to set variables that don't exist - // since there's no current buffer - lyx_view_->getDialogs().hideBufferDependent(); - } else { - lyx_view_->setBuffer(theBufferList().first()); - } - } + + theBufferList().close(lyx_view_->buffer(), true); }