diff --git a/src/context.cc b/src/context.cc index 93bf8a7fe..2ed0c51c0 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 9967cb70b..f75e36c73 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; }; }