From d6b69cb6f7818d5fb9d01007828a385eaf1308dc Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 23 Apr 2015 20:15:17 +0100 Subject: [PATCH] Fix :open bug that could set a deleted buffer as the last used one --- src/buffer_manager.cc | 6 ------ src/buffer_manager.hh | 1 - src/commands.cc | 13 ++++++++++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index 996eafd2..09ee1aca 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -70,12 +70,6 @@ void BufferManager::delete_buffer(Buffer& buffer) kak_assert(false); } -void BufferManager::delete_buffer_if_exists(StringView name) -{ - if (Buffer* buf = get_buffer_ifp(name)) - delete_buffer(*buf); -} - Buffer* BufferManager::get_buffer_ifp(StringView name) { auto path = real_path(parse_filename(name)); diff --git a/src/buffer_manager.hh b/src/buffer_manager.hh index 8dab6df7..ec321b7f 100644 --- a/src/buffer_manager.hh +++ b/src/buffer_manager.hh @@ -22,7 +22,6 @@ public: void unregister_buffer(Buffer& buffer); void delete_buffer(Buffer& buffer); - void delete_buffer_if_exists(StringView name); iterator begin() const { return m_buffers.cbegin(); } iterator end() const { return m_buffers.cend(); } diff --git a/src/commands.cc b/src/commands.cc index 7f515172..2b5f75da 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -132,16 +132,22 @@ void edit(const ParametersParser& parser, Context& context) auto& name = parser.positional_count() > 0 ? parser[0] : context.buffer().name(); + auto& buffer_manager = BufferManager::instance(); Buffer* buffer = nullptr; Buffer* oldbuf = &context.buffer(); if (not force_reload) - buffer = BufferManager::instance().get_buffer_ifp(name); + buffer = buffer_manager.get_buffer_ifp(name); if (not buffer) { if (parser.get_switch("scratch")) { - BufferManager::instance().delete_buffer_if_exists(name); + if (Buffer* buf = buffer_manager.get_buffer_ifp(name)) + { + buffer_manager.delete_buffer(*buf); + if (buf == oldbuf) + oldbuf = nullptr; + } buffer = new Buffer(name, Buffer::Flags::None); } else if (auto fifo = parser.get_switch("fifo")) @@ -160,7 +166,8 @@ void edit(const ParametersParser& parser, Context& context) } } - BufferManager::instance().set_last_used_buffer(*oldbuf); + if (oldbuf) + buffer_manager.set_last_used_buffer(*oldbuf); const size_t param_count = parser.positional_count(); if (buffer != &context.buffer() or param_count > 1)