From f230feec7f18fcea705cd4d6e507d2256d1658f8 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 28 Sep 2012 14:14:49 +0200 Subject: [PATCH] Change buffer order based on the last one used --- src/buffer_manager.cc | 10 ++++++++++ src/buffer_manager.hh | 1 + src/commands.cc | 2 ++ 3 files changed, 13 insertions(+) diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index 75d0e94c..d2f7857f 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -52,6 +52,16 @@ Buffer* BufferManager::get_buffer(const String& name) return nullptr; } +void BufferManager::set_last_used_buffer(Buffer& buffer) +{ + auto it = m_buffers.begin(); + while (*it != &buffer and it != m_buffers.end()) + ++it; + assert(it != m_buffers.end()); + m_buffers.erase(it); + m_buffers.emplace(m_buffers.begin(), &buffer); +} + CandidateList BufferManager::complete_buffername(const String& prefix, CharCount cursor_pos) { diff --git a/src/buffer_manager.hh b/src/buffer_manager.hh index fd6ca23f..ca84c9e8 100644 --- a/src/buffer_manager.hh +++ b/src/buffer_manager.hh @@ -27,6 +27,7 @@ public: size_t count() const { return m_buffers.size(); } Buffer* get_buffer(const String& name); + void set_last_used_buffer(Buffer& buffer); CandidateList complete_buffername(const String& prefix, CharCount cursor_pos = -1); diff --git a/src/commands.cc b/src/commands.cc index 3e02cb26..6b7cfccd 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -288,6 +288,7 @@ void edit(const CommandParameters& params, Context& context) buffer = open_or_create(name, context); } + BufferManager::instance().set_last_used_buffer(*buffer); Window& window = *buffer->get_or_create_window(); if (param_count > 1) @@ -382,6 +383,7 @@ void show_buffer(const CommandParameters& params, Context& context) if (not buffer) throw runtime_error("buffer " + buffer_name + " does not exists"); + BufferManager::instance().set_last_used_buffer(*buffer); context.change_editor(*buffer->get_or_create_window()); }