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();