From 9455303a1e143f878b9f0617a840575ce732f640 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 6 Jan 2014 20:07:08 +0000 Subject: [PATCH] Do not allow changing buffer when the context is editing --- src/context.cc | 10 ++++++++-- src/context.hh | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/context.cc b/src/context.cc index d4ad1616..887a9a37 100644 --- a/src/context.cc +++ b/src/context.cc @@ -159,6 +159,8 @@ void Context::forget_jumps_to_buffer(Buffer& buffer) void Context::change_buffer(Buffer& buffer) { + if (m_edition_level > 0) + throw runtime_error("the current buffer is still being edited"); m_window.reset(); if (has_client()) client().change_buffer(buffer); @@ -192,12 +194,16 @@ std::vector Context::selections_content() const void Context::begin_edition() { - ++m_edition_level; + if (m_edition_level >= 0) + ++m_edition_level; } void Context::end_edition() { - kak_assert(m_edition_level > 0); + if (m_edition_level < 0) + return; + + kak_assert(m_edition_level != 0); if (m_edition_level == 1) buffer().commit_undo_group(); diff --git a/src/context.hh b/src/context.hh index 60d76c71..9a8a0277 100644 --- a/src/context.hh +++ b/src/context.hh @@ -72,7 +72,7 @@ public: void set_name(String name) { m_name = std::move(name); } bool is_editing() const { return m_edition_level!= 0; } - void disable_undo_handling() { ++m_edition_level; } + void disable_undo_handling() { m_edition_level = -1; } private: void begin_edition(); void end_edition();