Always allow to delete a buffer, just recreate a scratch buffer if needed
Fixes #850
This commit is contained in:
parent
5af29b0254
commit
cc2affea11
|
@ -57,11 +57,11 @@ void BufferManager::delete_buffer(Buffer& buffer)
|
||||||
{ return p.get() == &buffer; });
|
{ return p.get() == &buffer; });
|
||||||
kak_assert(it != m_buffers.end());
|
kak_assert(it != m_buffers.end());
|
||||||
|
|
||||||
ClientManager::instance().ensure_no_client_uses_buffer(buffer);
|
|
||||||
|
|
||||||
m_buffer_trash.emplace_back(std::move(*it));
|
m_buffer_trash.emplace_back(std::move(*it));
|
||||||
m_buffers.erase(it);
|
m_buffers.erase(it);
|
||||||
|
|
||||||
|
ClientManager::instance().ensure_no_client_uses_buffer(buffer);
|
||||||
|
|
||||||
buffer.on_unregistered();
|
buffer.on_unregistered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,8 @@ void Client::change_buffer(Buffer& buffer)
|
||||||
if (m_buffer_reload_dialog_opened)
|
if (m_buffer_reload_dialog_opened)
|
||||||
close_buffer_reload_dialog();
|
close_buffer_reload_dialog();
|
||||||
|
|
||||||
m_last_buffer = &m_window->buffer();
|
auto* current = &m_window->buffer();
|
||||||
|
m_last_buffer = contains(BufferManager::instance(), current) ? current : nullptr;
|
||||||
|
|
||||||
auto& client_manager = ClientManager::instance();
|
auto& client_manager = ClientManager::instance();
|
||||||
m_window->options().unregister_watcher(*this);
|
m_window->options().unregister_watcher(*this);
|
||||||
|
|
|
@ -109,33 +109,21 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer)
|
||||||
{
|
{
|
||||||
for (auto& client : m_clients)
|
for (auto& client : m_clients)
|
||||||
{
|
{
|
||||||
client->context().jump_list().forget_buffer(buffer);
|
auto& context = client->context();
|
||||||
|
context.jump_list().forget_buffer(buffer);
|
||||||
if (client->last_buffer() == &buffer)
|
if (client->last_buffer() == &buffer)
|
||||||
client->set_last_buffer(nullptr);
|
client->set_last_buffer(nullptr);
|
||||||
|
|
||||||
if (&client->context().buffer() != &buffer)
|
if (&context.buffer() != &buffer)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (client->context().is_editing())
|
if (context.is_editing())
|
||||||
throw runtime_error(format("client '{}' is inserting in buffer '{}'",
|
throw runtime_error(format("client '{}' is inserting in buffer '{}'",
|
||||||
client->context().name(),
|
context.name(),
|
||||||
buffer.display_name()));
|
buffer.display_name()));
|
||||||
|
|
||||||
if (Buffer* last_buffer = client->last_buffer())
|
Buffer* last = client->last_buffer();
|
||||||
{
|
context.change_buffer(last ? *last : BufferManager::instance().get_first_buffer());
|
||||||
client->context().change_buffer(*last_buffer);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& buf : BufferManager::instance())
|
|
||||||
{
|
|
||||||
if (buf.get() != &buffer)
|
|
||||||
{
|
|
||||||
client->context().change_buffer(*buf);
|
|
||||||
client->set_last_buffer(nullptr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
auto end = std::remove_if(m_free_windows.begin(), m_free_windows.end(),
|
auto end = std::remove_if(m_free_windows.begin(), m_free_windows.end(),
|
||||||
[&buffer](const WindowAndSelections& ws)
|
[&buffer](const WindowAndSelections& ws)
|
||||||
|
|
|
@ -566,9 +566,6 @@ void delete_buffer(const ParametersParser& parser, Context& context, const Shell
|
||||||
if (not force and (buffer.flags() & Buffer::Flags::File) and buffer.is_modified())
|
if (not force and (buffer.flags() & Buffer::Flags::File) and buffer.is_modified())
|
||||||
throw runtime_error(format("buffer '{}' is modified", buffer.name()));
|
throw runtime_error(format("buffer '{}' is modified", buffer.name()));
|
||||||
|
|
||||||
if (manager.count() == 1)
|
|
||||||
throw runtime_error(format("buffer '{}' is the last one", buffer.name()));
|
|
||||||
|
|
||||||
manager.delete_buffer(buffer);
|
manager.delete_buffer(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user