mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-29 01:24:52 +03:00
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; });
|
||||
kak_assert(it != m_buffers.end());
|
||||
|
||||
ClientManager::instance().ensure_no_client_uses_buffer(buffer);
|
||||
|
||||
m_buffer_trash.emplace_back(std::move(*it));
|
||||
m_buffers.erase(it);
|
||||
|
||||
ClientManager::instance().ensure_no_client_uses_buffer(buffer);
|
||||
|
||||
buffer.on_unregistered();
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,8 @@ void Client::change_buffer(Buffer& buffer)
|
||||
if (m_buffer_reload_dialog_opened)
|
||||
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();
|
||||
m_window->options().unregister_watcher(*this);
|
||||
|
@ -109,33 +109,21 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer)
|
||||
{
|
||||
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)
|
||||
client->set_last_buffer(nullptr);
|
||||
|
||||
if (&client->context().buffer() != &buffer)
|
||||
if (&context.buffer() != &buffer)
|
||||
continue;
|
||||
|
||||
if (client->context().is_editing())
|
||||
if (context.is_editing())
|
||||
throw runtime_error(format("client '{}' is inserting in buffer '{}'",
|
||||
client->context().name(),
|
||||
context.name(),
|
||||
buffer.display_name()));
|
||||
|
||||
if (Buffer* last_buffer = client->last_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;
|
||||
}
|
||||
}
|
||||
Buffer* last = client->last_buffer();
|
||||
context.change_buffer(last ? *last : BufferManager::instance().get_first_buffer());
|
||||
}
|
||||
auto end = std::remove_if(m_free_windows.begin(), m_free_windows.end(),
|
||||
[&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())
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user