From 4b06c09c684b633a9cb746c7dbe3d715cf5c6777 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 12 Dec 2017 18:22:05 +1100 Subject: [PATCH] Make `edit` command work fine when running from an empty context This way, the kind of context we get from a piped command allows for opening a buffer and working with it directly. --- src/commands.cc | 6 ++++-- src/context.cc | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 8ee19c49..cbb21cb7 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -249,11 +249,13 @@ void edit(const ParametersParser& parser, Context& context, const ShellContext&) buffer->flags() &= ~Buffer::Flags::NoHooks; } + Buffer* current_buffer = context.has_buffer() ? &context.buffer() : nullptr; + const size_t param_count = parser.positional_count(); - if (buffer != &context.buffer() or param_count > 1) + if (current_buffer and (buffer != current_buffer or param_count > 1)) context.push_jump(); - if (buffer != &context.buffer()) + if (buffer != current_buffer) context.change_buffer(*buffer); if (param_count > 1 and not parser[1].empty()) diff --git a/src/context.cc b/src/context.cc index ef2a999f..da23aac1 100644 --- a/src/context.cc +++ b/src/context.cc @@ -159,10 +159,10 @@ void JumpList::forget_buffer(Buffer& buffer) void Context::change_buffer(Buffer& buffer) { - if (&buffer == &this->buffer()) + if (has_buffer() and &buffer == &this->buffer()) return; - if (m_edition_level > 0) + if (has_buffer() and m_edition_level > 0) this->buffer().commit_undo_group(); m_window.reset();