Fix :open bug that could set a deleted buffer as the last used one

This commit is contained in:
Maxime Coste 2015-04-23 20:15:17 +01:00
parent 80fb8aa60d
commit d6b69cb6f7
3 changed files with 10 additions and 10 deletions

View File

@ -70,12 +70,6 @@ void BufferManager::delete_buffer(Buffer& buffer)
kak_assert(false); 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) Buffer* BufferManager::get_buffer_ifp(StringView name)
{ {
auto path = real_path(parse_filename(name)); auto path = real_path(parse_filename(name));

View File

@ -22,7 +22,6 @@ public:
void unregister_buffer(Buffer& buffer); void unregister_buffer(Buffer& buffer);
void delete_buffer(Buffer& buffer); void delete_buffer(Buffer& buffer);
void delete_buffer_if_exists(StringView name);
iterator begin() const { return m_buffers.cbegin(); } iterator begin() const { return m_buffers.cbegin(); }
iterator end() const { return m_buffers.cend(); } iterator end() const { return m_buffers.cend(); }

View File

@ -132,16 +132,22 @@ void edit(const ParametersParser& parser, Context& context)
auto& name = parser.positional_count() > 0 ? parser[0] auto& name = parser.positional_count() > 0 ? parser[0]
: context.buffer().name(); : context.buffer().name();
auto& buffer_manager = BufferManager::instance();
Buffer* buffer = nullptr; Buffer* buffer = nullptr;
Buffer* oldbuf = &context.buffer(); Buffer* oldbuf = &context.buffer();
if (not force_reload) if (not force_reload)
buffer = BufferManager::instance().get_buffer_ifp(name); buffer = buffer_manager.get_buffer_ifp(name);
if (not buffer) if (not buffer)
{ {
if (parser.get_switch("scratch")) 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); buffer = new Buffer(name, Buffer::Flags::None);
} }
else if (auto fifo = parser.get_switch("fifo")) 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(); const size_t param_count = parser.positional_count();
if (buffer != &context.buffer() or param_count > 1) if (buffer != &context.buffer() or param_count > 1)