From 6f4515f005d41c03ed18766e68544cb5aca7b8c4 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 19 Jan 2017 18:44:26 +0000 Subject: [PATCH] Only touch new clients selections when target coord are explicit Do not implicitely change new clients selections to target coordinates when the user did not specify them, so that we can re-use the selections from the found free window, which is the generally desired behaviour. --- src/client.cc | 2 ++ src/client_manager.cc | 13 ++++++++----- src/client_manager.hh | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) 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(); }