From 729e55573f15017c043293e9f79ce27168e76533 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 10 Oct 2014 14:00:24 +0100 Subject: [PATCH] Support changing buffer when an edition is in progress --- src/context.cc | 8 +++++++- src/context.hh | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/context.cc b/src/context.cc index 93bf8a7f..2ed0c51c 100644 --- a/src/context.cc +++ b/src/context.cc @@ -170,8 +170,14 @@ void Context::forget_jumps_to_buffer(Buffer& buffer) void Context::change_buffer(Buffer& buffer) { + if (&buffer == &this->buffer()) + return; + if (m_edition_level > 0) - throw runtime_error("the current buffer is still being edited"); + { + this->buffer().commit_undo_group(); + m_edition_level = 0; + } m_window.reset(); if (has_client()) client().change_buffer(buffer); diff --git a/src/context.hh b/src/context.hh index 9967cb70..f75e36c7 100644 --- a/src/context.hh +++ b/src/context.hh @@ -113,15 +113,21 @@ private: struct ScopedEdition { ScopedEdition(Context& context) - : m_context(context) + : m_context(context), m_buffer(&context.buffer()) { m_context.begin_edition(); } ~ScopedEdition() - { m_context.end_edition(); } + { + // If buffer changed, the edition count + // was reset. + if (m_buffer == &m_context.buffer()) + m_context.end_edition(); + } Context& context() const { return m_context; } private: Context& m_context; + safe_ptr m_buffer; }; }