diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2023-01-06 08:36:57 +0100 |
|---|---|---|
| committer | Johannes Altmanninger <aclopte@gmail.com> | 2023-01-08 17:26:15 +0100 |
| commit | 4f7d7a5e33318be766b7f46d21f18e54e2291250 (patch) | |
| tree | 11fe257b409ca463034ad4a017ea48dcda4d1b1a /src/client_manager.cc | |
| parent | 938be7a7b0fb0753329bc74735e4d9d2132ea28c (diff) | |
Fix regression when file on command line cannot be opened
Commit 933e4a599 (Load buffer in command line order, 2022-12-06)
introduced a regression: the command
$ kak /boot/grub/grub.cfg
Fatal error: no such buffer '/boot/grub/grub.cfg'
quits with no indication of the underlying error.
Prior to 933e4a599, it would open the *scratch* buffer instead,
and show an error in the status line, pointing to the debug buffer,
which would contain:
error while opening file '/boot/grub/grub.cfg':
/boot/grub/grub.cfg: Permission denied
Let's fix this scenario by matching the old behavior.
Diffstat (limited to 'src/client_manager.cc')
| -rw-r--r-- | src/client_manager.cc | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/client_manager.cc b/src/client_manager.cc index 5453f02c..0f601fc1 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -50,10 +50,13 @@ Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui, int pi StringView init_buffer, Optional<BufferCoord> init_coord, Client::OnExitCallback on_exit) { - Buffer& buffer = init_buffer.empty() ? BufferManager::instance().get_first_buffer() - : BufferManager::instance().get_buffer(init_buffer); + Buffer* buffer = nullptr; + if (not init_buffer.empty()) + buffer = BufferManager::instance().get_buffer_ifp(init_buffer); + if (buffer == nullptr) + buffer = &BufferManager::instance().get_first_buffer(); - WindowAndSelections ws = get_free_window(buffer); + WindowAndSelections ws = get_free_window(*buffer); Client* client = new Client{std::move(ui), std::move(ws.window), std::move(ws.selections), pid, std::move(env_vars), @@ -64,7 +67,7 @@ Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui, int pi if (init_coord) { auto& selections = client->context().selections_write_only(); - selections = SelectionList(buffer, buffer.clamp(*init_coord)); + selections = SelectionList(*buffer, buffer->clamp(*init_coord)); client->context().window().center_line(init_coord->line); } |
