diff --git a/src/client.cc b/src/client.cc index f4e9e37bf..078122227 100644 --- a/src/client.cc +++ b/src/client.cc @@ -55,6 +55,8 @@ Client::~Client() { m_window->options().unregister_watcher(*this); m_window->set_client(nullptr); + ClientManager::instance().add_free_window(std::move(m_window), + std::move(context().selections())); } bool Client::process_pending_inputs() diff --git a/src/client_manager.cc b/src/client_manager.cc index f2989b908..c7246a822 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -19,11 +19,11 @@ ClientManager::~ClientManager() void ClientManager::clear() { - m_free_windows.clear(); // So that clients destructor find the client manager empty // so that local UI does not fork. ClientList clients = std::move(m_clients); m_client_trash.clear(); + m_free_windows.clear(); } String ClientManager::generate_name() const @@ -38,7 +38,7 @@ String ClientManager::generate_name() const Client* ClientManager::create_client(std::unique_ptr&& ui, EnvVarMap env_vars, StringView init_cmds, - BufferCoord init_coord) + Optional init_coord) { Buffer& buffer = BufferManager::instance().get_first_buffer(); WindowAndSelections ws = get_free_window(buffer); @@ -47,9 +47,12 @@ Client* ClientManager::create_client(std::unique_ptr&& ui, generate_name()}; m_clients.emplace_back(client); - auto& selections = client->context().selections_write_only(); - selections = SelectionList(buffer, buffer.clamp(init_coord)); - client->context().window().center_line(init_coord.line); + if (init_coord) + { + auto& selections = client->context().selections_write_only(); + selections = SelectionList(buffer, buffer.clamp(*init_coord)); + client->context().window().center_line(init_coord->line); + } try { diff --git a/src/client_manager.hh b/src/client_manager.hh index 6b7cac636..8ebfaa37d 100644 --- a/src/client_manager.hh +++ b/src/client_manager.hh @@ -22,7 +22,7 @@ public: Client* create_client(std::unique_ptr&& ui, EnvVarMap env_vars, StringView init_cmds, - BufferCoord init_coord); + Optional init_coord); bool empty() const { return m_clients.empty(); } size_t count() const { return m_clients.size(); }